﻿var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
	$("#popupContactClose").show();
	var iframeHtml = "<iframe id=videoframe src ='"+$("#currentvideolink").attr("value")+"' width='750' height='500' frameborder='0' marginheight='0' marginwidth='0' scrolling=no></iframe>";
	//alert(iframeHtml);

  
  $("#videoPopupContact").html(iframeHtml);	
  //$("#popupContact").append("<div align='center' class='text'><a id='VideopopupContactClose' href='#'>Close 3 window </a></div>");
		$("#backgroundPopup").css({
			"opacity": "0.9"
		});
		$("#backgroundPopup").fadeIn(2000,function(){
		$("#flash_ff").hide();
		$("#homeExpectFF").hide();	
$("#leaderboardAd").hide();
		$("img[title='Back 1 panels']").hide();	
		$("img[title='Forward 1 panels']").hide();	
			$("#popupContact").fadeIn(1000);
			
		});
		
		popupStatus = 1;
		
	}

}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupContactClose").hide();
	$("#videoPopupContact").html("");	
	    $("#popupContact").fadeOut(1000,function(){
		$("#backgroundPopup").fadeOut(1000,function(){
$("#leaderboardAd").show();
		$("#homeExpectFF").show();	
		$("img[title='Back 1 panels']").show();	
		$("img[title='Forward 1 panels']").show();	
		$("#flash_ff").fadeIn(2000);
		
		});
		
			
		});
		
		 //$("#backgroundPopup").fadeOut(2500,function(){
		 //$("#flash_ff").show();
		
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var top1 = document.documentElement.scrollTop;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": top1+(windowHeight/2-popupHeight/2),
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": top1+windowHeight,
		"width" :windowWidth
		
	});
	
}
function slideSwitch() {


    var $active = $('#slideshow DIV.active');


    if ( $active.length == 0 ) $active = $('#slideshow DIV.latest_detail:last');

    var $next =  $active.next("DIV.latest_detail").length ? $active.next("DIV.latest_detail"): $('#slideshow DIV.latest_detail:first');
	
	 $active.fadeOut(0,function() {
	$next.fadeIn(0);
	  $active.removeClass('active');
	   $next.addClass('active');
	   $("#slideshownumber").text($next.attr("title"));
	   showDot("latest_detail"+$next.attr("title"),"latest_dot","");
 	 
	});
	

}


function backSlideSwitch() {

    var $active = $('#slideshow DIV.active');	
    if ( $active.length == 0 ) $active = $('#slideshow DIV.latest_detail:first');	
    var $next =  $active.prev("DIV.latest_detail").length ? $active.prev("DIV.latest_detail"): $('#slideshow DIV.latest_detail:last');
	$active.removeClass('active');
$active.hide();
$next.addClass('active');
 $("#slideshownumber").text($next.attr("title"));
	   $next.show();
	   showDot("latest_detail"+$next.attr("title"),"latest_dot","");
}

function nextSlideSwitch() {

    var $active = $('#slideshow DIV.active');	
    if ( $active.length == 0 ) $active = $('#slideshow DIV.latest_detail:last');	
    var $next =  $active.next("DIV.latest_detail").length ? $active.next("DIV.latest_detail"): $('#slideshow DIV.latest_detail:first');
	$active.removeClass('active');
$active.hide();
$next.addClass('active');
 $("#slideshownumber").text($next.attr("title"));
	   $next.show();
	   showDot("latest_detail"+$next.attr("title"),"latest_dot","");
}

function showDot(itemid,displayid,id){

var item = document.getElementById(itemid );
var displayname="#"+displayid;
var displaytext=".......";
var defaultdisplaytext="&nbsp;";


if (displayid=="video_dot"){
	var temp="#"+"videoduration"+id;
	var duration=$(temp).attr("value");
	displaytext=displaytext+" "+duration;
	defaultdisplaytext=displaytext;
}

if (item.scrollHeight > item.clientHeight){

	$(displayname).text(displaytext);
}else{
$(displayname).html(defaultdisplaytext);
}
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	$("#currentvideolink").attr("value",$("#videolink1").attr("value"));			
	var slideshowid = setInterval( "slideSwitch()", 10000);
	
	showDot("sme_detail1","sme_dot","");
	showDot("video_detail1","video_dot","1");
	showDot("latest_detail1","latest_dot","");
	
	$("#popupContact").hide();
	
	$("#backbutton").click(function(){
		clearInterval( slideshowid);
		backSlideSwitch();
		slideshowid = setInterval( "slideSwitch()", 10000);
		return false;
	});
	
	$("#nextbutton").click(function(){
		clearInterval( slideshowid);
		nextSlideSwitch();
		slideshowid = setInterval( "slideSwitch()", 10000);
		return false;
	});
	
	$("#pausebutton").click(function(){
		clearInterval( slideshowid);		
		return false;
	});
	
	//LOADING POPUP	
	$("a[name=videohyperlink],a[name=videohyperlinktext]").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		return false;
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
		return false;
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	
	$("#videobox #pagination-flickr li ").click(function(){

	var number=$(this).attr("title");
	var st ;
	var st_a;	
	st="#video_detail"+number;
st_a="#videobox #pagination-flickr li[title='"+number+"']  a";	
var st_b="#videobox #pagination-flickr li[class='active'] ";	

$(st_b).text("");
$(st_b).append("<a href='#'>"+$(st_b).attr("title")+"</a></li>");
		
	 $("div.video_detail").hide();
	 $(st).show();
	 
	 $("#videobox #pagination-flickr li ").removeClass('active'); 

	$(this).addClass('active'); 

	$(st_a).replaceWith(number); 
	
	var videolinkid = "#videolink"+number;
	$("#currentvideolink").attr("value",$(videolinkid).attr("value"));
	showDot("video_detail"+number,"video_dot",number);
	
	
	return false;
	
	});

	$("#smebox #pagination-flickr li ").click(function(){

	var number=$(this).attr("title");
	var st = "#sme_detail"+number;
	var st_a ="#smebox #pagination-flickr li[title='"+number+"']  a";;	
	var st_b="#smebox #pagination-flickr li[class='active'] ";	

$(st_b).text("");
$(st_b).append("<a href='#'>"+$(st_b).attr("title")+"</a></li>");
		
	 $("div.sme_detail").hide();
	 $(st).show();
	 
	 
	 
	 $("#smebox #pagination-flickr li ").removeClass('active'); 

	$(this).addClass('active'); 

	$(st_a).replaceWith(number); 

	
	showDot("sme_detail"+number,"sme_dot","");
	
	return false;
	
	});


});
