var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;


$(document).ready(function(){
//runOnLoad(function(){	
	
						   
	$("#nav_pages div.t").hide();
	
	$("#nav_pages div.t:first").addClass("dd");
	$("#nav_pages div.t.dd").show();
	$("#p_nav a").filter(':contains(Prev)').hide()
	//hide next and prev
	
		if($("#nav_pages div.t").length<=1)
			  {
				  $("#p_nav").hide()

			  }
			  
	//next
	    $("#p_nav a").filter(':contains(Next)').click( function() {
		//alert("Hello");
		$("#nav_pages div.t").hide();
		$("#nav_pages div.t.dd").next().show(1,function(){
			 // alert($("#nav_pages div").length)
			 // alert($("#nav_pages div").index( $(this)[0] ))
			  if($("#nav_pages div.t").index( $(this)[0] )< $("#nav_pages div.t").length-1)
			  {
				  $("#p_nav a").filter(':contains(Prev)').show()
				  $("div.t.dd").next().addClass("dd");
				  $("div.t.dd:first").removeClass("dd");
				  //$("#nav_pages div.dd").hide();
				  //$("div.dd").show();
			  }else{
					  $("#p_nav a").filter(':contains(Next)').hide();
					  $("#p_nav a").filter(':contains(Prev)').show();
					  $("#nav_pages div.t").removeClass("dd");
					  $("#nav_pages div.t:last").addClass("dd");
				  }
		});
	} );
	//prev		
		$("#p_nav a").filter(':contains(Prev)').click( function() {
			//alert("Hello");
			$("#nav_pages div.t").hide();
			$("#nav_pages div.t.dd").prev().show(1, function(){
				 // alert($("#nav_pages div").length)
				 // alert($("#nav_pages div").index( $(this)[0] ))
				  if($("#nav_pages div.t").index( $(this)[0] )>0)
				  {
					  $("#p_nav a").filter(':contains(Next)').show()
					  $("div.t.dd").prev().addClass("dd");
					  $("div.t.dd:last").removeClass("dd");
					  //$("#nav_pages div.dd").hide();
					  //$("div.dd").show();
					  
				  }else{
					  $("#p_nav a").filter(':contains(Prev)').hide();
					  $("#p_nav a").filter(':contains(Next)').show();
					  $("#nav_pages div.t").removeClass("dd");
					  $("#nav_pages div.t:first").addClass("dd");
				  }
			});
	} );
		
// table tr hovering in blue color		
	$(".admn_table tr").hover(function(){
		  $(this).addClass("highl");
		},function(){
		  $(this).removeClass("highl");
	});
//---end table overing effect
//mouse over effect for image page
	//$("#img_cont").hide();
	$(".p_gallery_img img").hover(function(e){
		  $("#img_cont").html("<img/>");
		  $("#img_cont img").attr("src", this.src);
		  //$("#img_cont").css({ display: "block" });
		  $("#img_cont").show(1);
		 // $().mousemove(function(e)  
			//{  
				$("#img_cont").css({ top:  e.pageY });
				$("#img_cont").css({ left:  e.pageX +35});
				//$('p').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);  
			//}); 
		},function(){
		  //$("#img_cont").css({ display: "none" });
		 $("#img_cont").hide();
	});
//---end mouse over effect for image page
//photo gallery
/*			var new_width;
			var new_height;
			var wsize=125;
			var hsize=125;
		$(".photo_gallery img").each(function(){
											  
			var aspect_ratio = $(this).width()/$(this).height(); 
			var dest_ratio=wsize/hsize;
			if (dest_ratio < aspect_ratio) {
				$(this).width(hsize);
				$(this).height(hsize/aspect_ratio);
			}else{
				$(this).height(wsize);
				$(this).width(wsize*aspect_ratio);

			}
//			if($(this).width() < $(this).height()){
	//		alert($(this).attr("src"))
			//}
		})
			$(".photo_gallery img").hover(function(e){
			  $("#img_cont").html("<img/>");
			  $("#img_cont img").attr("src", this.src);
			  //$("#img_cont").css({ display: "block" });
			  $("#img_cont").show(1);
			 // $().mousemove(function(e)  
				//{  
					$("#img_cont").css({ top:  e.pageY });
					$("#img_cont").css({ left:  e.pageX +35});
					//$('p').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);  
				//}); 
			},function(){
			  //$("#img_cont").css({ display: "none" });
			 $("#img_cont").hide();
		});		*/
		
//---end photo gallery
//News RSS--------------------------
	//$("#cli").bind("click", function(){
			var test = new Array(4);
			test[0]='http://www.environmental-expert.com/RSS.asp?idproducttype=8&level=7';
			test[1]='http://www.environmental-expert.com/RSS.asp?idproducttype=8&level=5';
			test[2]='http://www.environmental-expert.com/RSS.asp?idproducttype=8&level=6';
			test[3]='http://www.environmental-expert.com/RSS.asp?idproducttype=8&level=1';
			//alert(test[Math.floor(Math.random()*4)]+"::::"+Math.floor(Math.random()*4))
			var feed_url=test[Math.floor(Math.random()*4)];
			if($(feed_url)=="") {
				alert("Please enter a valid RSS url");						 
			}
			else if(window['google']){
			var feed = new google.feeds.Feed(feed_url);
			feed.setNumEntries(13);
			feed.load(function(result) {
 
				 if (!result.error) {
					 
					var maxfeed = result.feed.entries.length;
					$("#rss_news").empty()
					
					//var div = document.createElement("div");
					//var div = document.createElement("div");
					var newsh =document.createElement("div");
					$(newsh).addClass('headline');
					for (var i = 0; i < maxfeed; i++) {
					
					  var entry = result.feed.entries[i];
					//  var div2 = document.createElement("div");
					//alert("mod="+i%2+"val="+ i);
				
					if(entry.title.length > 60)
					{
					//	$(div2).append("<li><strong>"+ entry.publishedDate + "</strong><br /><a target='_blank' href="+ entry.link +">" +entry.title+"</a></li>" );
						$(newsh).append("<div><a target='_blank' href="+ entry.link +">" +entry.title.substring(0, 60)+"...</a></div>");
					}else{
						$(newsh).append("<div><a target='_blank' href="+ entry.link +">"+entry.title+"</a></div>");
					}
						//$(div2).append("");
						//if($("#content").is(":checked"))	$(div2).append("<p class='data'>"+ entry.content + "</p>" );
						//$(div2).attr("class", "int");
						//$(div2).hide();
						//$(div2).fadeIn(2000, function(){$(".int").fadeIn(2000);	});
						//$(ul).append($(test));
						
						//$(newsh).append($(div));
						if(i%3==0 && i<maxfeed-1){
							//alert("mod="+i%2+"val="+ i);
						//var div = document.createElement("div");
						var newsh =document.createElement("div");
						$(newsh).addClass('headline');
						}
						$("#rss_news").append($(newsh));
						
						//$(".int").fadeIn(2000);
						//$("div:hidden:first").show(i*3000);
						
						
					}
					
	
				  $(".int:eq(0)").show("1", function () {
					$(this).next().show("1", arguments.callee); 
				  });
	
					//--news scroller
				  headline_count = $("div.headline").size();
				  $("div.headline:eq("+current_headline+")").css('top', '10px');
				  headline_interval = setInterval(headline_rotate,5000);
				  $('#rss_news').hover(function() {
					clearInterval(headline_interval);
				  }, function() {
					headline_interval = setInterval(headline_rotate,5000);
					headline_rotate();
				  });
				//end news scroller
				}//alert($("#rss_news li").length)
							   
			});
		}
	//});
//----end News Rss
//-- director page hovering
		//$("#img_nav div").hide();
					
			$(".img_nav div").hover(function(){
		  $(this).addClass("sel");
		},function(){
		  $(this).removeClass("sel");
		});
//---end  director page hovering

});


function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count;
    $("div.headline:eq(" + old_headline + ")")
	.animate({top: -170},"slow", function() {
	  $(this).css('top', '170px');
	});


	  $("div.headline:eq(" + current_headline + ")")
	.animate({top: 10},"slow");
  old_headline = current_headline;
}