// JavaScript Document



//if (jQuery.browser.msie) {
if (jQuery.browser.msie) {	
	
	jQuery(window).load(function(){	 
		
		
		$(document).ready(function(){

	// MENU AUTO HIDE
	var auto_hide = true; //Set to false to disable menu auto hide
	var footer = true; //Set to false to hide footer bar
	var active = true;
	
	function movemenu(action){
		if(action == 'hide'){
			$('#footer.auto_hide').animate({ marginBottom: "-50px" }, 500 );
			$('#menu-main.auto_hide').animate({ marginTop: "-75px" }, 500 );
			active = false;
		}else if(action == 'show'){
			$('#footer.auto_hide').animate({ marginBottom: "0px" }, 500 );
		 	$('#menu-main.auto_hide').animate({ marginTop: "0px" }, 500 );
			active = true;
		}
	}
	
	if(footer == false ){ $('#footer').hide(); }
	
	$(function() {
		setInterval(function() {		
							 
			if(active&&auto_hide){
				active = false;
				movemenu('hide');
			}
		}, 3000);
	});
					 
	$(document).mousemove( function(e) {
		 if(auto_hide){
		 movemenu('show');
		 active = true;
		 }
	});
		
	// SCROLL PANEL INITIALIZE		
	$(function(){
		$('.scroll').jScrollPane();
	});

	// MANAGE SHOW/HIDE COMMENTS BUTTON

	$('#showComments').click(function(){
									  
		$('#tab1').fadeTo("slow", 0); 
		$('#tab1').css('display','none');
		$('#tab2').fadeTo("slow", 1);  
		$('#right1').fadeTo("slow", 0); 
		$('#right1').css('display','none');
		$('#right2').fadeTo("slow", 1);  		
		$('#showComments').hide();  	
		$('#showContent').show();	
		$('.scroll').jScrollPane();
		 
		return false;
		
	});	
	$('#showContent').click(function(){ 
									 
		$('#tab2').fadeTo("slow", 0); 
		$('#tab2').css('display','none');
		$('#tab1').fadeTo("slow", 1);  	
		$('#right2').fadeTo("slow", 0); 
		$('#right2').css('display','none');
		$('#right1').fadeTo("slow", 1);  
		$('#showContent').hide();  	
		$('#showComments').show();	
		$('.scroll').jScrollPane();
		 
		return false;
		
	});	
	
	// FADE EFFECTS
 
	//portfolio thumb fadein fadeout
	$(".image img").css("opacity",1); 
	$(".image").hover(function(){
		$(this).find("img").fadeTo("slow", .3);
		$(this).find("span.title,span.description").fadeTo("slow", 1); 

	}, function(){
		$(this).find("img").fadeTo("slow", 1);
		$(this).find("span.fadeout,span.description").fadeTo("slow", 0); 
	});
	
	//blog thumb fadein fadeout
	$(".post img").css("opacity",1); 
	
	$(".show").css("opacity",0);
	$(".post").hover(function(){
		$(this).find("div.extract, div.extract p").fadeTo("slow", 1);
		$(this).find("div.postdata,div.postdata span").fadeTo("slow", 0); 

	}, function(){
		$(this).find("div.extract, div.extract p").fadeTo("slow", 0);
		$(this).find("div.postdata, div.postdata span").fadeTo("slow", 1); 
	});
	
	
	// CONTACT FORM AJAX MANAGEMENT
 
	// in contact.html
	/*$("#main-contact-form").submit(function(){
		// 'this' refers to the current submitted form 
		var str = $(this).serialize();
		$.ajax({
			type: "POST",
			url: "wp-content/themes/tasteit/contactmanager.php",
			data: str,
			success: function(msg){
				$("#note").ajaxComplete(function(event, request, settings){
					if(msg == 'OK'){ // Message Sent? Show the 'Thank You' message and hide the form
						result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
						$("#fields").hide();
					} else {
						result = msg;
					}
					$(this).html(result);
				});
			}
		});
		return false;
	});*/
	
	
	 // MY BKGALLERY SCRIPT TO MANAGE BACKGROUND IMAGES
	
	var actualimg = 1;
	var totalimages = jQuery('#bkgallery img').length;
   	var skip_transition = false;
    var imagewidth = jQuery('#bkgallery #im1').width();
    var imageheight = jQuery('#bkgallery #im1').height();
	var ratio = imageheight/imagewidth;
	   
	if(totalimages == 1){jQuery('#bkgallery a').hide();}
	
	
	 
    	supersizeImage(jQuery('#bkgallery #im1'), ratio);
    
    jQuery(window).resize(function() {
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			
			supersizeImage(jQuery('#im'+actualimg), ratio);
    });
	
	function fadeImage(action){
		if(skip_transition == false){
			
			
			 
			jQuery('#bkgallery img').fadeOut(1500);
			if(action == "prev"){
				actualimg = actualimg-1;
				if(actualimg < 1){actualimg = totalimages;}
			}else if(action == "next"){
				actualimg = actualimg+1;
				if(actualimg > totalimages){ actualimg = 1;}
			} 
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			
			supersizeImage(jQuery('#im'+actualimg), ratio);
			jQuery('#im'+actualimg).fadeIn(1500);
		}
		skip_transition = false; 
	}
   
    jQuery(function() {
        if(totalimages >1 &&skip_transition == false ){
			
            setInterval(function() {   
				 
				fadeImage( 'next');
            }, 7000);
        } 
    });
	
	jQuery('#bkgallery a').click(function(){
		skip_transition = false; 
		var action = (jQuery(this).attr('class'));
		
		fadeImage(action);
		skip_transition = true;
		return false;
	});
	
	jQuery(document).keydown(function(event) {
		 
	  	if (event.keyCode == '39') { //NEXT
		 	jQuery('#bkgallery .next').click();
	   	}else  if (event.keyCode == '37') { //PREV
		 	jQuery('#bkgallery .prev').click();
	   	}
	   	 
	});

	// SUPERSIZE FUNCTION TO MANAGE SCREEN RATIO FIT FOR BACKGROUND IMAGE  

	

    function supersizeImage(image, ratios) {
		
       
	   
	   //alert(imagewidth + " - "+imageheight);
       var browserwidth = jQuery(window).width();
       var browserheight = jQuery(window).height();
 	   if(imageheight == 0){imageheight = jQuery(image).attr('height');}
       
		
	    
		
       if ((browserheight/browserwidth) >= ratios){//si la pantalla es mas alta que ancha (respecto al ratio
               jQuery(image).height(browserheight);
               jQuery(image).width(browserheight / ratios); 
       } else { 
	   			 
               jQuery(image).width(browserwidth);
               jQuery(image).height(browserwidth * ratios);    
       }
     
       jQuery(image).css('left', (browserwidth - jQuery(image).width())/2);
       if(jQuery(image).height()>0){
       		jQuery(image).css('top', (browserheight - jQuery(image).height())/2);
       }
	}

 
});  
	   

$(document).ready(function(){ 

	// MENU SCRIPT
	
	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;
	
	function jsddm_open()
	{  jsddm_canceltimer();
	   jsddm_close();
	   ddmenuitem = $(this).find('ul').css('display', 'block');}
	
	function jsddm_close()
	{  if(ddmenuitem) ddmenuitem.css('display', 'none');}
	
	function jsddm_timer()
	{  closetimer = window.setTimeout(jsddm_close, timeout);}
	
	function jsddm_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
		  closetimer = null;}}

 

	$('#menu-main > li').bind('mouseover', jsddm_open)
	$('#menu-main > li').bind('mouseout',  jsddm_timer)
	$('.menu > li').bind('mouseover', jsddm_open)
	$('.menu > li').bind('mouseout',  jsddm_timer)

	
	document.onclick = jsddm_close;

});	
		
		
								 
	});

}else{

$(document).ready(function(){
						    
	$('#bkgallery').css({'display' : 'none'});				   
						   
	jQuery(window).load(function(){	
	$('#bkgallery').fadeIn('slow');	
	$('.loading').css({'display' : 'none'});
								 
	// MENU AUTO HIDE
	var auto_hide = true; //Set to false to disable menu auto hide
	var footer = true; //Set to false to hide footer bar
	var active = true;
	
	function movemenu(action){
		if(action == 'hide'){
			$('#footer.auto_hide').animate({ marginBottom: "-50px" }, 500 );
			$('#menu-main.auto_hide').animate({ marginTop: "-75px" }, 500 );
			active = false;
		}else if(action == 'show'){
			$('#footer.auto_hide').animate({ marginBottom: "0px" }, 500 );
		 	$('#menu-main.auto_hide').animate({ marginTop: "0px" }, 500 );
			active = true;
		}
	}
	
	if(footer == false ){ $('#footer').hide(); }
	
	$(function() {
		setInterval(function() {		
							 
			if(active&&auto_hide){
				active = false;
				movemenu('hide');
			}
		}, 3000);
	});
					 
	$(document).mousemove( function(e) {
		 if(auto_hide){
		 movemenu('show');
		 active = true;
		 }
	});
		
	// SCROLL PANEL INITIALIZE		
	$(function(){
		$('.scroll').jScrollPane();
	});

	// MANAGE SHOW/HIDE COMMENTS BUTTON

	$('#showComments').click(function(){
									  
		$('#tab1').fadeTo("slow", 0); 
		$('#tab1').css('display','none');
		$('#tab2').fadeTo("slow", 1);  
		$('#right1').fadeTo("slow", 0); 
		$('#right1').css('display','none');
		$('#right2').fadeTo("slow", 1);  		
		$('#showComments').hide();  	
		$('#showContent').show();	
		$('.scroll').jScrollPane();
		 
		return false;
		
	});	
	$('#showContent').click(function(){ 
									 
		$('#tab2').fadeTo("slow", 0); 
		$('#tab2').css('display','none');
		$('#tab1').fadeTo("slow", 1);  	
		$('#right2').fadeTo("slow", 0); 
		$('#right2').css('display','none');
		$('#right1').fadeTo("slow", 1);  
		$('#showContent').hide();  	
		$('#showComments').show();	
		$('.scroll').jScrollPane();
		 
		return false;
		
	});	
	
	// FADE EFFECTS
 
	//portfolio thumb fadein fadeout
	$(".image img").css("opacity",1); 
	$(".image").hover(function(){
		$(this).find("img").fadeTo("slow", .3);
		$(this).find("span.title,span.description").fadeTo("slow", 1); 

	}, function(){
		$(this).find("img").fadeTo("slow", 1);
		$(this).find("span.fadeout,span.description").fadeTo("slow", 0); 
	});
	
	//blog thumb fadein fadeout
	$(".post img").css("opacity",1); 
	
	$(".show").css("opacity",0);
	$(".post").hover(function(){
		$(this).find("div.extract, div.extract p").fadeTo("slow", 1);
		$(this).find("div.postdata,div.postdata span").fadeTo("slow", 0); 

	}, function(){
		$(this).find("div.extract, div.extract p").fadeTo("slow", 0);
		$(this).find("div.postdata, div.postdata span").fadeTo("slow", 1); 
	});
	
	
	// CONTACT FORM AJAX MANAGEMENT

 
	// in contact.html
	/*$("#main-contact-form").submit(function(){
		// 'this' refers to the current submitted form
		var str = $(this).serialize();
		$.ajax({
			type: "POST",
			url: "wp-content/themes/tasteit/contactmanager.php",
			data: str,
			success: function(msg){
				$("#note").ajaxComplete(function(event, request, settings){
					if(msg == 'OK'){ // Message Sent? Show the 'Thank You' message and hide the form
						result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
						$("#fields").hide();
					} else {
						result = msg;
					}
					$(this).html(result);
				});
			}
		});
		return false;
	});*/
	
	
	 // MY BKGALLERY SCRIPT TO MANAGE BACKGROUND IMAGES
	
	var actualimg = 1;
	var totalimages = jQuery('#bkgallery img').length;
   	var skip_transition = false;
    var imagewidth = jQuery('#bkgallery #im1').width();
    var imageheight = jQuery('#bkgallery #im1').height();
	var ratio = imageheight/imagewidth;
	   
	if(totalimages == 1){jQuery('#bkgallery a').hide();}
	
	
	 
    	supersizeImage(jQuery('#bkgallery #im1'), ratio);
    
    jQuery(window).resize(function() {
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			
			supersizeImage(jQuery('#im'+actualimg), ratio);
    });
	
	function fadeImage(action){
		if(skip_transition == false){
			
			
			 
			jQuery('#bkgallery img').fadeOut(1500);
			if(action == "prev"){
				actualimg = actualimg-1;
				if(actualimg < 1){actualimg = totalimages;}
			}else if(action == "next"){
				actualimg = actualimg+1;
				if(actualimg > totalimages){ actualimg = 1;}
			} 
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			
			supersizeImage(jQuery('#im'+actualimg), ratio);
			jQuery('#im'+actualimg).fadeIn(1500);
		}
		skip_transition = false; 
	}
   
    jQuery(function() {
        if(totalimages >1 &&skip_transition == false ){
			
            setInterval(function() {   
				 
				fadeImage( 'next');
            }, 7000);
        } 
    });
	
	jQuery('#bkgallery a').click(function(){
		skip_transition = false; 
		var action = (jQuery(this).attr('class'));
		
		fadeImage(action);
		skip_transition = true;
		return false;
	});
	
	jQuery(document).keydown(function(event) {
		 
	  	if (event.keyCode == '39') { //NEXT
		 	jQuery('#bkgallery .next').click();
	   	}else  if (event.keyCode == '37') { //PREV
		 	jQuery('#bkgallery .prev').click();
	   	}
	   	 
	});

	// SUPERSIZE FUNCTION TO MANAGE SCREEN RATIO FIT FOR BACKGROUND IMAGE  

	

    function supersizeImage(image, ratios) {
		
       
	   
	   //alert(imagewidth + " - "+imageheight);
       var browserwidth = jQuery(window).width();
       var browserheight = jQuery(window).height();
 	   if(imageheight == 0){imageheight = jQuery(image).attr('height');}
       
		
	    
		
       if ((browserheight/browserwidth) >= ratios){//si la pantalla es mas alta que ancha (respecto al ratio
               jQuery(image).height(browserheight);
               jQuery(image).width(browserheight / ratios); 
       } else { 
	   			 
               jQuery(image).width(browserwidth);
               jQuery(image).height(browserwidth * ratios);    
       }
     
       jQuery(image).css('left', (browserwidth - jQuery(image).width())/2);
       if(jQuery(image).height()>0){
       		jQuery(image).css('top', (browserheight - jQuery(image).height())/2);
       }
	}

 	});	
});  
	   

$(document).ready(function(){ 

	// MENU SCRIPT
	
	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;
	
	function jsddm_open()
	{  jsddm_canceltimer();
	   jsddm_close();
	   ddmenuitem = $(this).find('ul').css('display', 'block');}
	
	function jsddm_close()
	{  if(ddmenuitem) ddmenuitem.css('display', 'none');}
	
	function jsddm_timer()
	{  closetimer = window.setTimeout(jsddm_close, timeout);}
	
	function jsddm_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
		  closetimer = null;}}

 

	$('#menu-main > li').bind('mouseover', jsddm_open)
	$('#menu-main > li').bind('mouseout',  jsddm_timer)
	$('.menu > li').bind('mouseover', jsddm_open)
	$('.menu > li').bind('mouseout',  jsddm_timer)

	
	document.onclick = jsddm_close;

});	
 
}

