// JavaScript Document
// Home Slider
function viewEvent(margina){
	$("#homeEventsOverflower").animate({ marginLeft: margina+"px" }, 800 );
}

// Home Tabs
var TabbedContent = {
	init: function() {	
		$(".tab_item").mouseover(function() {
		
			var background = $(this).parent().find(".moving_bg");
			
			$(background).stop().animate({
				left: $(this).position()['left']
			}, {
				duration: 300
			});
			
			TabbedContent.slideContent($(this));
			
		});
	},
	
	slideContent: function(obj) {
		
		var margin = $(obj).parent().parent().find(".slide_content").width();
		margin = margin * ($(obj).prevAll().size() - 1);
		margin = margin * -1;
		
		$(obj).parent().parent().find(".tabslider").stop().animate({
			marginLeft: margin + "px"
		}, {
			duration: 300
		});
	}
}

$(document).ready(function() {
	TabbedContent.init();
});


// Home select news
$(document).ready(function() {	

	//Show Banner
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser				
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});

	
});//Close Function

//slider
$(document).ready(function() {

	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel .pozicija").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});

// Popup

popup1 = "";
function rsg(psjs_url){
    if(popup1){
        if(popup1.closed){
            popup1 = window.open("http://rsg.promotim.ba/assets/live/rsg.htm", "popup1", "top=50,left=50,width=290,height=150,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
        } else { 
            popup1.focus();
        }
    } else {
        popup1 = window.open("http://rsg.promotim.ba/assets/live/rsg.htm", "popup1", "top=50,left=50,width=290,height=150,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
    }
}
function rsg1(psjs_url){
    if(popup1){
        if(popup1.closed){
            popup1 = window.open("http://rsg.promotim.ba/assets/live/rsg1.htm", "popup1", "top=50,left=50,width=290,height=150,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
        } else { 
            popup1.focus();
        }
    } else {
        popup1 = window.open("http://rsg.promotim.ba/assets/live/rsg1.htm", "popup1", "top=50,left=50,width=290,height=150,resizable=0,toolbar=0,scrollbars=0,location=0,status=0,menubar=0")
    }
}

function check(){
	
}
/*
function check(id,iddva){
	var obj = $(id);
	var objdva = $(iddva);
	var objhtml = obj.html();
	if (objhtml ==  '<span class="span2"></span>' || objhtml ==  '<span class="span2"> </span>'){
		obj.html('');
		objdva.remove();
	}
}
*/
