//Front end Java Script File

var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

jQuery(document).ready(function() 
{	
	 //code for home page random images effect  
	jQuery('#headerImagesDissolve').cycle({timeout:5000, random:1,cleartype:true});
	
	
	/*code for left menu arrows i.e. for portfolio categories*/
	if(jQuery("#portfolioCategoriesList li:first").attr("class")=="existing")
	jQuery("#top").removeClass("arrows_hover").css({'cursor':'default'});
	
	if(jQuery("#portfolioCategoriesList li:last").attr("class")=="existing")
	jQuery("#bottom").removeClass("arrows_hover").css({'cursor':'default'});
	
	//if(!jQuery("#portfolioCategoriesList li a").hasClass("selected"))
	//jQuery("#top").removeClass("arrows_hover").css({'cursor':'default'});
	
	
	/* =============================================== Fading effect for thumbnails ================================================= */	
	 	

	 jQuery('.portfolio_thumbnail_inner').css('display','none');
	 jQuery('#mycarousel').css('display','none');
	 jQuery('.portfolio_thumbnail_inner').animate({'opacity':0});
	 jQuery('#mycarousel').animate({'opacity':0});
  
	  jQuery(".portfolio_container").hover(
      function () 
      {  
      	  //wrapperBox mouseover
		  jQuery('.portfolio_thumbnail_inner').css('display','block');
		  jQuery('#mycarousel').css('display','block');
		  
		  jQuery('.portfolio_thumbnail_inner').stop().animate({'opacity':1},600);
		  jQuery('#mycarousel').stop().animate({'opacity':1},600);
							
      }, 
      function () 
      { //mouseout code
      
		   jQuery('.portfolio_thumbnail_inner').stop().animate({'opacity':0},600);
		   jQuery('#mycarousel').stop().animate({'opacity':0},600);
		
		   if(browser=="Microsoft Internet Explorer")
		   {
				 jQuery('.portfolio_thumbnail_inner').css('display','none');
			     jQuery('#mycarousel').css('display','none');
			}
		 		
      });
   /* =============================================== End of Fading effect for thumbnails ========================================*/
   
	//code for getting hover color change effect for arrows
    jQuery(".arrows_hover").hover(
      function () 
      {  //.wrapperBox mouseover
		  $(this).stop().animate({ backgroundColor: "#007abc" }, 300);
							
      }, 
      function () 
      { //mouseout code
      
		 $(this).stop().animate({ backgroundColor: "#000" }, 300);
		 		
      });
  
});

	
		/*...............................................................................................
	Images slide show configuration
		all the elements specified should be given  
			eg if "slideShowHandlesContainer" is the id of the container then it should be given as #slideShowHandlesContainer
				if the same is class then it should be ".slideShowHandlesContainer" etc
 ................................................................................................*/
	

	imagesSlideShowImagesContainer = 	".slider_content"; 
	textSlideShowTextContainer     =    ".portfolio_description";
	
/*...............................................................................................
	Images slide show configuration
 ................................................................................................*/
//slider content images sliding function
jQuery(document).ready(function(){
	//counter to hold the current image
	currentSlideImagesCount = 0;
	
	previousElement=0;
	
	globalImgId=0;
	
	curElem=0;
	
	prevElem=0;
	//get all the images for slid show
	var $slidingImages = jQuery(imagesSlideShowImagesContainer+" img");
	
	var $slidingTexts  = jQuery(".portfolio_short_desc");
	
	//alert($slidingImages.length);
	jQuery(".jcarousel-prev").css({'display':'none'});

	//proceed only if the there are more than 1 image
	if($slidingImages.length>=1)
	{
		//hide all other images
		$slidingImages.css({"display":"none"});
		
		//$slidingTexts.css({"display":"none"});
		
		jQuery(".portfolio_short_desc").css({"display":"none"});
		
		//get the first image being displayed
		$slidingImagesFirstImage = $slidingImages[currentSlideImagesCount];
		
		$slidingTextxFirstText = $slidingTexts[currentSlideImagesCount];

		//display the first image
		jQuery($slidingImagesFirstImage).css({"display":"block"});
		
		//alert($slidingTextxFirstText);
		jQuery($slidingTextxFirstText).css({"display":"block"});
		
	} 
	
	
	jQuery('.thumbImages').click(function()
		 {

			//alert($slidingImages.length);
			imgId=this.id;
			str_arr=imgId.split('_');
			currentElement=str_arr[1];
			currentSlideImagesCount=currentElement;
			globalImgId=currentSlideImagesCount;
			
			if(currentSlideImagesCount==($slidingImages.length-1))
			{
				jQuery(".jcarousel-next").css({'display':'none'});
				jQuery(".jcarousel-prev").css({'display':'block'});
			}
			else
			{	
				jQuery(".jcarousel-prev").css({'display':'block'});
				jQuery(".jcarousel-next").css({'display':'block'});
			}
			
			if(currentSlideImagesCount==0)
			{
				jQuery(".jcarousel-prev").css({'display':'none'});
				jQuery(".jcarousel-next").css({'display':'block'});
			}
			
			
			jQuery($slidingImages[previousElement]).fadeOut("slow",function()
			{
				//	jQuery($slidingTexts[previousElement]).fadeOut("slow");
				jQuery($slidingTexts[previousElement]).css({"display":"none"});
		
				previousElement=currentSlideImagesCount;								
				
			}); //end of previous element fadeout
			
			jQuery($slidingImages[currentSlideImagesCount]).fadeIn("slow",function()
			{
				//jQuery($slidingTexts[currentSlideImagesCount]).fadeIn("slow");
				jQuery($slidingTexts[currentSlideImagesCount]).css({"display":"block"});		
			});
			
	});//end of thumbnails click
	
	
	
	jQuery(".jcarousel-next").click(function()
	{
		//alert(globalImgId);
		//nextElem=globalImgId;
		if(jQuery(".jcarousel-prev").css('display')=='none')
		jQuery(".jcarousel-prev").css({'display':'block'});
		
		curElem=parseInt(globalImgId)+1;
		
		if(prevElem<0)
		prevElem=parseInt(globalImgId)-1;
		else
		prevElem=parseInt(globalImgId);
		
		
		if(curElem==($slidingImages.length-1))
		jQuery(".jcarousel-next").css({'display':'none'});
		
			jQuery($slidingImages[(prevElem)]).fadeOut("slow",function()
			{
				//jQuery($slidingTexts[currentSlideImagesCount]).fadeIn("slow");
				jQuery($slidingTexts[prevElem]).css({"display":"none"});
				//previousElement=parseInt(prevElem)-1;
			});
		
			
			
			jQuery($slidingImages[(curElem)]).fadeIn("slow",function()
			{
				//jQuery($slidingTexts[currentSlideImagesCount]).fadeIn("slow");
				jQuery($slidingTexts[curElem]).css({"display":"block"});	
				
				previousElement=parseInt(curElem);	
			});
					
			globalImgId=curElem;
			
		 });//end of thumbnails click
	
	
	jQuery(".jcarousel-prev").click(function()
	{
	
		//alert(globalImgId);
		curElem=parseInt(globalImgId)-1;
		
		if(prevElem<0)
		prevElem=parseInt(globalImgId)-1;
		else
		prevElem=parseInt(globalImgId);
		
	
		
		if(prevElem==($slidingImages.length-1))
		jQuery(".jcarousel-next").css({'display':'block'});
		
		if(globalImgId==1)
		jQuery(".jcarousel-prev").css({'display':'none'});
		
		//alert("curElem"+curElem+"prevElem"+prevElem);
		
		jQuery($slidingImages[(prevElem)]).fadeOut("slow",function()
				{
					//jQuery($slidingTexts[currentSlideImagesCount]).fadeIn("slow");
					jQuery($slidingTexts[prevElem]).css({"display":"none"});
					
				});
		
			
			
		jQuery($slidingImages[(curElem)]).fadeIn("slow",function()
				{
					//jQuery($slidingTexts[currentSlideImagesCount]).fadeIn("slow");
					jQuery($slidingTexts[curElem]).css({"display":"block"});	
					previousElement=parseInt(curElem);		
				});
					
		globalImgId=curElem;
		
		
	});
	 /* =============================================== End of Fading effect for next previous thumbnails ==========*/
	
	//hover effect for portfolio catgories menu on the left side and for all a tags in top menu(profile, contacts etc)
	 jQuery(".links_hover").hover(
      function () 
      {  //.wrapperBox mouseover
          jQuery(this).stop().not(".selected").not(".menu_selected").animate({color:'#007abc'},{duration:300,queue:false});
       	//jQuery(this).stop().animate({color:'#007abc'},{duration:300,queue:false});
							
      }, 
      function () 
      { //.wrapperBox mouseout
        //	jQuery(this).stop().animate({color:'#000'},{duration:150,queue:false});
        	jQuery(this).stop().not(".selected").not(".menu_selected").animate({color:'#000'},{duration:150});
    	
   
      });
      
      //hover effect for a tags in the portfolio project description text
      jQuery(".portfolio_description a").hover(
      function () 
      {  
      
       		jQuery(this).stop().animate({color:'#007abc'},{duration:300,queue:false});
							
      }, 
      function () 
      { 
        	jQuery(this).stop().animate({color:'#000'},{duration:150,queue:false});
      
      });
     
     //getting body id
     pageBodyId=jQuery("body").attr('id');
     
     //setting the top menu as selected if respective menu is clicked
    if(pageBodyId=='profile' || pageBodyId=='constituents' || pageBodyId=='contact')
    jQuery("#menu_"+pageBodyId+" a").addClass("menu_selected");
    
    
	
	
}); //end of DOM ready

  /* =============================================== Code for getting next and previous portfolio categories projects ================*/
PrevURL='';
firstURL='';

jQuery(document).ready(function() 
{
	
		if(jQuery("#portfolioCategoriesList li a").hasClass('selected'))
		{
			PrevURL=jQuery(".selected").attr('href');
		}
		else
		{
			firstURL=jQuery("#portfolioCategoriesList li :first").attr('href');
			jQuery("#bottom").attr("href",firstURL);	
		}
		
		
		jQuery("#bottom").click(function()
		{
	
			nextPrev=jQuery(".next").attr('href');
			jQuery("#bottom").attr("href",nextPrev);
	
			
		});
	
	PrevURL=jQuery("#"+jQuery('.existing').prev('li').attr('id')+" a").attr('href');
	jQuery("#top").attr("href",PrevURL);	
	
	
	
});

 /* =============================================== Code for Ticker tape =================================================*/

jQuery(document).ready(function()
	{
	
		totalUlWidth=0;
		totalUlPadding=0;
	
		totalUlLength=jQuery("#firstTicker li").length;
		totalUlPadding=parseInt(totalUlLength*4);
		jQuery("#firstTicker li").css({"float":"left"});
		
	
		jQuery("#firstTicker li").each(function()
		{
		//	alert(jQuery(this).width());
			totalUlWidth+=jQuery(this).width();
		});
		
		jQuery(".ticker_scroller_main").css({'width': (((totalUlWidth+totalUlPadding)*2)+4)+'px'});
		jQuery("#firstTicker").css({'width': (totalUlWidth+totalUlPadding+2)+'px'});
		jQuery("#SecondTicker").css({'width': (totalUlWidth+totalUlPadding+2)+'px'});
		
		getNextTicker(totalUlWidth,totalUlPadding);
	
	
	jQuery(".ticker_scroller_main").hover(function()
	{
		//jQuery(this).stop();
	},
	function()
	{
		//getNextTicker(totalUlWidth,totalUlPadding);
	});
	
	
	});
	
	//function for ticker
	function getNextTicker(totalUlWidth,totalUlPadding)
	{
	
		//jQuery(".ticker_scroller_main").animate({left:-(totalUlWidth+totalUlPadding)+'px'},{ duration:10000, complete:function()
			//{
				//jQuery("#firstTicker").css({'float':'right'});
				
				jQuery(".ticker_scroller_main").animate({left: '-='+ (totalUlWidth+totalUlPadding)}, 35000, "linear", function()
				{
					
						if(jQuery("#firstTicker").hasClass('ticker_left'))
						{
							jQuery("#firstTicker").removeClass("ticker_left");
							jQuery("#firstTicker").addClass("ticker_right");
						}
						else
						{
							jQuery("#firstTicker").removeClass("ticker_right");
							jQuery("#firstTicker").addClass("ticker_left");
						}
						
						if(jQuery("#SecondTicker").hasClass("ticker_right"))
						{
							jQuery("#SecondTicker").removeClass("ticker_right");
							jQuery("#SecondTicker").addClass("ticker_left");
						}
						else
						{
							jQuery("#SecondTicker").removeClass("ticker_left");
							jQuery("#SecondTicker").addClass("ticker_right");
						}
					
					jQuery(".ticker_scroller_main").css({'left':0+'px'});
					//ulLeft=jQuery("#firstTicker").css("float");
		
					getNextTicker(totalUlWidth,totalUlPadding);
			//}});
			});
		
	}
	
	 /* =============================================== End of Ticker tape code =================================================*/