// functions

function fBookmarkLink() {
	title = "PlanMySite.com - New Jersey web design agency"; 
	url = "http://planmysite.com";
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} 
	else if(window.external) { 
		window.external.AddFavorite( url, title); 
	}
	else if(window.opera && window.print) { 
		return true; 
	}
}

function inputhover(idhover, special) { 
	var elemID = document.getElementById(idhover).className; 
	var last = elemID.substr(elemID.length - 5, 5); 
	var sze = document.getElementById(idhover).scrollWidth; 
	var obj, style; 
	if(document.getElementById && (obj = document.getElementById(idhover)) && (style = obj.style)) { 
		if( last != "send")
			style.backgroundPosition = '-'+sze+'px 0'; 
		else
			style.backgroundPosition = '-57px 0'; 
		if(special == 1) 
			obj.focused = true;
		if ( last == "tnorm" || last == "onial") 
			style.borderBottom = '1px #494846 solid'; 
	} 
} 

function inputhoverstop(idhover, special) { 
	var elemID = document.getElementById(idhover).className; 
	var last = elemID.substr(elemID.length - 5, 5); 
	var obj, style; 
	if(document.getElementById && (obj = document.getElementById(idhover)) && (style = obj.style)) { 
		if(obj.focused == true && special == 0) 
			return true;
		style.backgroundPosition = '0px 0'; 
		if(special == 1) 
			obj.focused = false;
		if ( last == "tnorm" || last == "onial" )  
			style.borderBottom = '1px #adaca5 solid'; 
	} 
}
 
// Index Project Rotation
var iProjectImgControl=0;
var iProjectLinkControl=0;
var iProjectCount;
var iProjectLinksCount; 
 
function nextProjectIndex() {
	jQuery(".index-project-control span img:eq("+iProjectImgControl+")").hide();
	jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").hide();	  
	if (iProjectImgControl != iProjectCount) {
		iProjectImgControl = iProjectImgControl+1;
		iProjectLinkControl = iProjectLinkControl+1;
	}
	else {
		iProjectImgControl = 0;	  
		iProjectLinkControl = 0;	  
	}
	jQuery(".index-project-control span img:eq("+iProjectImgControl+")").fadeIn("slow");  	  
	jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").fadeIn("slow");		
}  

/* Case study images rotation*/
var iScreenControl = 0;
var iScreenCount;

function nextScreen() {
	jQuery(".screen-controler span img:eq("+iScreenControl+")").hide();  
	if (iScreenControl != iScreenCount) {
		iScreenControl = iScreenControl+1;
	}
	else {
		iScreenControl = 0;	    
	}
	jQuery(".screen-controler span img:eq("+iScreenControl+")").fadeIn("slow");  	  	
} 


var bLoginArea = true;
function fLoginArea(control) {
	if(bLoginArea)
	{
		if(control == 1)
		{
			jQuery("#t-already-a-client").addClass("a-already-a-client-active");
			jQuery("#login-area").show();
		}
		else			
		{
			jQuery("#t-already-a-client").removeClass("a-already-a-client-active");
			jQuery("#login-area").hide();
		}
	}
}

jQuery(document).ready(function(){
	//
	jQuery("#t-already-a-client, #login-area").hover( 
		function () {
			fLoginArea(1);
		},  
		function () {
			fLoginArea(0);
		}
	);	
	
	jQuery("#t-already-a-client, #login-area").children().not('a, label').click( 
		function () 
		{
			fLoginArea(1);
			return false; 
		}
	);		
	
	jQuery(".log-in").click(
		function() 
		{
			jQuery("#login-form").submit();
		}
	);
	
	jQuery("#login-area input").focus(
		function() {
			bLoginArea = false;
		}
	);
	
	jQuery("#login-area input").blur(
		function() {
			bLoginArea = true;
		}
	);	
	
	jQuery("body").click(
		function() {
			bLoginArea = true;
			fLoginArea(0);				
		}
	);		
	
	jQuery("#login-area input").hover( 
		function () {
			jQuery(this).css({'color':'#fefefe'});
		},  
		function () {
			jQuery(this).css({'color':'#a4a4a4'});
		}
	);		
	
	jQuery("#login-area input").focus(
		function() {
		jQuery(this).css({'color':'#fefefe'});
		}
	);
	
	jQuery("#login-area input").blur(
		function() {
		jQuery(this).css({'color':'#a4a4a4'});
		}
	);
	
	// Testi full
	jQuery("#testi-more").click(
		function() {
			jQuery("#testi-more").hide();
			jQuery(".testimonial-more").slideDown();
		}
	);
	
	// Add to fav
	if(window.opera && window.print) { 
	jQuery("#t-add-to-favorite").attr("href","http://planmysite.com");
	jQuery("#t-add-to-favorite").attr("rel","sidebar");
	};	
	jQuery("#t-add-to-favorite").click(
		function() {
			fBookmarkLink();
		}
	);
	
	// Index rotation
	var projectFooterInterval;
	var iProjectFooter = jQuery("#already-trusted-logos > a").length;
	
	jQuery("#already-trusted-logos img, #client-list img, #awards-list img").fadeTo(0, 0.55); 
	jQuery("#already-trusted-logos img, #client-list img, #awards-list img").hover( 
		function () {
			jQuery(this).fadeTo("fast", 1);
		},  
		function () {
			jQuery(this).fadeTo(0, 0.55);
		}
	);
	

	// Rotation footer
	/*iProjectFooter = iProjectFooter-1;
	var iFooterControl=0;
	var iFooterControl2;
	function rotationFooter() {
		iFooterControl = iFooterControl+1;
		iFooterControl2 = iFooterControl+1;	
		if(iFooterControl > iProjectFooter)
		{
			alert("Case 2:"+iFooterControl+""+iProjectFooter+"");
			iFooterControl = 0;
			iFooterControl2 = 1;
		}
		else
		{
			alert("Case 3:"+iFooterControl+""+iProjectFooter+"");
			iFooterControl = iProjectFooter;
			iFooterControl2 = 0;
		}
		jQuery("#already-trusted-logos a").hide();
		alert("Wyswietlanie:"+iFooterControl+" | "+iFooterControl2+"");
		jQuery("#already-trusted-logos a:eq("+iFooterControl+")").fadeIn("slow");
		jQuery("#already-trusted-logos a:eq("+(iFooterControl2)+")").fadeIn("slow");

	}	
	
	projectIndexInterval = setInterval(rotationFooter,5000);
	*/
		
 
	// Index projects
	var projectIndexInterval;
	iProjectCount = jQuery(".index-project-control span > img").length-1;
	iProjectLinksCount = jQuery(".projects-links-control > a").length-1; 	
	
	projectIndexInterval = setInterval(nextProjectIndex,5000);
	
	jQuery(".index-project-control span img:eq("+iProjectImgControl+")").fadeIn();
	jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").fadeIn();
  
	jQuery(".index-project-control #prev").click( 
		function() {
			clearInterval(projectIndexInterval);
			projectIndexInterval = setInterval(nextProjectIndex,5000);		
			jQuery(".index-project-control span img:eq("+iProjectImgControl+")").hide();
			jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").hide();
			if (iProjectImgControl != 0) {
				iProjectImgControl = iProjectImgControl-1;
				iProjectLinkControl = iProjectLinkControl-1;
			}
			else {
				iProjectImgControl = iProjectCount;	  
				iProjectLinkControl = iProjectLinksCount; 
			}
			jQuery(".index-project-control span img:eq("+iProjectImgControl+")").fadeIn("slow");  	  
			jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").fadeIn("slow");	  
		}
	);
	
	jQuery(".index-project-control #next").click( 
		function() {
			clearInterval(projectIndexInterval);
			projectIndexInterval = setInterval(nextProjectIndex,5000);
			nextProjectIndex();		  
		}
	);	
  
	// About us
	jQuery("#about-team .person img,#about-team .person p").hover( 
		function () { 
			jQuery(this).parent().children('img').css({'background-color':'#000','background-color':'#000'})
			jQuery(this).parent().children('strong').css({'color':'#ffffff'})
			jQuery(this).parent().children('p').css({'background-color':'#000','color':'#ffffff'})
		},  
		function () { 
			jQuery(this).parent().children('img').css({'background-color':'#111','background-color':'#111'})
			jQuery(this).parent().children('strong').css({'color':'#aaaaaa'})
			jQuery(this).parent().children('p').css({'background':'none','color':'#666666'})
		} 
	); 
  
	// Dropdown menu
	var sMenuRel;
	jQuery('.m-services,.m-clients, .sub-menu a, .fsub-menu a').hover(  
		function() {
			sMenuRel = jQuery(this).attr('rel');
			jQuery(this).addClass("hover-menu");
			jQuery("."+sMenuRel+"").css({'display':'block'})
		},
		function() {
			jQuery(this).removeClass("hover-menu");
			jQuery("."+sMenuRel+"").css({'display':'none'})
		}
	); 
	
	jQuery('.service-menu a').hover(  
		function() {
			jQuery("#main-menu .m-services").addClass("hover-menu");
		},
		function() {
			jQuery("#main-menu .m-services").removeClass("hover-menu");
		}
	);	
	
	jQuery('.fservice-menu a').hover(  
		function() {
			jQuery("#footer-menu .m-services").addClass("hover-menu");
		},
		function() {
			jQuery("#footer-menu .m-services").removeClass("hover-menu");
		}
	);	
	
	jQuery('.projects-menu a').hover(  
		function() {
			jQuery("#main-menu .m-clients").addClass("hover-menu");
		},
		function() {
			jQuery("#main-menu .m-clients").removeClass("hover-menu");
		}
	);	
	
	jQuery('.fprojects-menu a').hover(  
		function() {
			jQuery("#footer-menu .m-clients").addClass("hover-menu");
		},
		function() {
			jQuery("#footer-menu .m-clients").removeClass("hover-menu");
		}
	);

	// Toggle services info
	var iHeight;
	iHeight = jQuery(".extended-version").height();
	 
	jQuery(".extended-version").css({'height':iHeight});
	jQuery(".view-extended").click(
		function () { 
			jQuery(".extended-version").slideDown("slow");
			jQuery(".view-extended").hide();
			jQuery(".view-short").show();
		}
	);

	jQuery(".view-short").click(
		function () { 
			jQuery(".extended-version").slideUp("slow");
			jQuery(".view-extended").show();
			jQuery(".view-short").hide();
		}
	);

	/* Client projection */
	jQuery("a.image-resume img, a.image-prev img, a.image-next img").show();
	jQuery("a.image-resume img, a.image-prev img, a.image-next img").fadeTo(0,0);
	
	jQuery("a.image-resume, a.image-prev, a.image-next").hover(
		function() {
			jQuery(this).children("img").stop().fadeTo('fast',0.50);						
		},
		function() {
			jQuery(this).children("img").stop().fadeTo('fast',0);			
		}
	);
	
	/* Arrow highlight */
	jQuery("a.image-next-rect").hover(
		function() {
			jQuery(this).parent().children("a.image-next").children("img").stop().fadeTo(0.5);
			jQuery(this).parent().children("a.image-next").children("img").fadeTo('fast',0.9);
		},
		function() {
			jQuery(this).children("img").fadeTo('fast',0.5).stop();
		}
	);	
	
	jQuery("a.image-prev-rect").hover(
		function() {
			jQuery(this).parent().children("a.image-prev").children("img").stop().fadeTo(0.5);
			jQuery(this).parent().children("a.image-prev").children("img").fadeTo('fast',0.9);
		},
		function() {
			jQuery(this).children("img").fadeTo('fast',0.5).stop();
		}
	);	
	
	jQuery("a.image-resume-rect").hover(
		function() {
			jQuery(this).parent().children("a.image-resume").children("img").stop().fadeTo(0.5);
			jQuery(this).parent().children("a.image-resume").children("img").fadeTo('fast',0.9);
		},
		function() {
			jQuery(this).children("img").fadeTo('fast',0.5).stop();
		}
	);		

	var screenInterval;
	iScreenCount = jQuery(".screen-controler span > img").length-1;
	screenInterval = setInterval(nextScreen,5000);
	
	jQuery(".screen-controler span img:eq("+iScreenControl+")").fadeIn();
  
	jQuery(".screen-controler .image-prev, .screen-controler a.image-prev-rect").click( 
		function() {
			clearInterval(screenInterval);
			iResumeControl = 0;
			jQuery("a.image-resume img").css({'top':''+iResumeControl*356+'px'});
			jQuery(".screen-controler span img:eq("+iScreenControl+")").hide();
			if (iScreenControl != 0) {
				iScreenControl = iScreenControl-1;
			}
			else {
				iScreenControl = iScreenCount;	  
			}
			jQuery(".screen-controler span img:eq("+iScreenControl+")").fadeIn("slow");  	    
		}
	);
	
	jQuery(".screen-controler .image-next, .screen-controler a.image-next-rect").click( 
		function() {
			clearInterval(screenInterval);
			nextScreen();		  
			iResumeControl = 0;
			jQuery("a.image-resume img").css({'top':''+iResumeControl*356+'px'});
		}
	);		
	
	var iResumeControl = -1;	
	jQuery(".image-resume, .image-resume-rect").click( 
		function() {
			if (iResumeControl == 0)
				{
					screenInterval = setInterval(nextScreen,5000);
					iResumeControl = -1;
				}
			else
				{
					clearInterval(screenInterval);
					iResumeControl = 0;
				}
				jQuery("a.image-resume img").css({'top':''+iResumeControl*356+'px'});		  
		}
	);		
	
	/* Printing */
	jQuery("ul.gallery li").hover(function() { //On hover...

		var thumbOver = jQuery(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		//alert(thumbOver);
		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		jQuery(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ')'});


		//Animate the image to 0 opacity (fade it out)
		jQuery(this).find("span").stop().fadeTo('normal', 0 , function() {
			jQuery(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		jQuery(this).find("span").stop().fadeTo('normal', 1).show();
	});
	
})

