$(document).ready(function(){						   
	//onfocus set val to null and on blur set val to default value
	$('.textbox').each(function() {
    var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});
	//onload load mainmenu function
	mainmenu();
	function mainmenu(){
	$("#menu-nav ul").css({display: "none"}); // Opera Fix
	$("#menu-nav li").hover(function(){
			$(this).addClass('hover');					 
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
			},function(){
			$(this).removeClass('hover');	
			$(this).find('ul:first').css({visibility: "hidden"});			
			});
	$("#menu-nav li:last-child").addClass("lilast").find("ul").addClass("ullast");

	}
	///////
	///  slideshow function goes here	
	/////
	$('#slideshow').cycle({ 
    speed:  'slow', 
    timeout: 5000, 
    pager:  '#slidemini', 
    pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#slidemini li:eq(' + idx + ') a'; 
		}     
	});

	//tab method goes here
	$('ul.tabNav li:first-child').addClass("current");
	$('div.tabContainer').find("div:first").addClass("current");
	$('ul.tabNav a').click(function() {
		var curChildIndex = $(this).parent().prevAll().length + 1;
		$(this).parent().parent().children('.current').removeClass('current');
		$(this).parent().addClass('current');
		$(this).parent().parent().next('.tabContainer').children('.current').fadeOut('fast',function() {
			$(this).removeClass('current');	
			$(this).parent().children('div:nth-child('+curChildIndex+')').fadeIn('slow',function() {
				$(this).addClass('current');
			});
		});
		return false;								
	});
	
	//Table
	$(".page table tr:odd").addClass("todd");
	 //////////
    // PrintArea
   ///////////
   $("#printBtn").click(function(){
		printfunc();						 
      //$(".innerpage").printArea();
	  //$('.innerpage').jqprint({ operaSupport: true });
   });
   // function to Print
   function printfunc()
	{ 
	  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
		  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
	  var content_vlue = $(".innerpage,.innerpage_contact").html();
	  
	  var docprint=window.open("","",disp_setting); 
	   docprint.document.open(); 
	   docprint.document.write('<html><head><title>PRoV International</title>'); 
	   docprint.document.write('</head><body onLoad="self.print()">');          
	   docprint.document.write(content_vlue);          
	   docprint.document.write('</body></html>'); 
	   docprint.document.close(); 
	   docprint.focus();
	   docprint.document.close(); 
	}
   //////////
    // Rss PopUp
   ///////////
   //When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) });		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 		
		return false;
	});	
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade').remove();  
	}); //fade them both out
		
		return false;
	});
	//remove border for last list child
	var co1en =$(".colone ul").find("li[class !=clear]").length;
	var lenn = parseInt(co1en)-1;
	$(".colone ul ").find("li").eq(lenn).css("border","none");

	//youtube gallery
	//if video is available load the function
	var videolist = $("ul.videolist li").length;
	if( videolist !=0 )
	{
	$("ul.videolist").ytplaylist({
				addThumbs:true, 
				autoPlay: true, 
				playerWidth: '320',
				playerHeight: '240',
				thumbSize: 'large',
				allowFullScreen: true,
				showInline: true
	
	});
	}
	//if video is available on home page load the function
	var homevideo = $("ul.homevideo li").length;
	if( homevideo !=0 )
	{
	$("ul.homevideo").ytplaylist({
				addThumbs:true, 
				autoPlay: true, 
				playerWidth: '216',
				playerHeight: '160',
				thumbSize: 'large',
				allowFullScreen: false,
				showInline: true
	
	});
	}
	$(".innerpage_contact").find("ul:even").addClass("ulodd");
});

