var actual_slide=1;
var timeout_slide;
jQuery.fn.toggleVal = function() {
	this.each(function() { $(this).focus(function() { if($(this).val() == this.defaultValue) { $(this).val(""); $(this).removeClass("toggleVal"); } }).blur(function() {if($(this).val() == "") { $(this).val(this.defaultValue); $(this).addClass("toggleVal"); }}); });
}
$(function() {

	if(jQuery.fn.defuscate) { $(".obfuscated").defuscate(); }

	if(jQuery.fn.toggleVal) { $(".togvalue").toggleVal(); }
	if(jQuery.fn.tooltip) { $(".tool_page").tooltip({ track: true, delay: 0, showURL: false, showBody: " - ", fade: 250 }); }
	
	if($.browser.msie && parseInt($.browser.version) < 7) {
		$("#content").css("backgroundImage", "url("+public_root_path+"/images/bgcontent.gif)");
		$("#partners").css("backgroundImage", "url("+public_root_path+"/images/bgpartners.jpg)");
	}

	$("a.favorite").click(function() {
		if (document.all) { window.external.AddFavorite(location.href, document.title); } 
		else if (window.sidebar) { window.sidebar.addPanel(document.title, location.href, ""); }
		return false;
	});

	$("a.goto").click(function() { var $tr = $(this.hash); $tr = $tr.length && $tr || $('[name=' + this.hash.slice(1) +']');
		if ($tr.length) { $('html,body').animate({scrollTop: $tr.offset().top}, 1000, 'bounceout'); /*, 'bounceout'*/ return false; } });
	
	$(".Lmenu, .LmenuSm").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#ffffff'},outcolor: {color: '#000000'}, speedcolor:400 });
	$(".catulpp").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#ffffff'},outcolor: {color: '#000000'}, speedcolor:400, click: function(e){
		e.preventDefault();
		var el = $(this).parent().parent().parent().parent();
		$(".projectinfo", el).hide();
		var rel = $("a", this).attr("rel");
		$("."+rel, el).fadeIn("slow");
	} });

	$(".Lmenu_sp").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#ffffff'},outcolor: {color: '#4f4f4f'}, speedcolor:400, click: function(e){
		e.preventDefault();
		var el = $(this).parent().parent().parent().parent();
		actual_slide = parseInt($("a", this).text());
		$(".lastprojectimg, .nameproject, .detailproject").fadeOut(2000);
		$(".rel_"+actual_slide).fadeIn(2000);
		clearTimeout(timeout_slide);
		timeout_slide = setTimeout("main_page_animate();", 15000);
	} });
	var ellmenu = $(".Lmenu_sp").html();
	if(ellmenu != "" && ellmenu != null && ellmenu != "undefined") timeout_slide = setTimeout("main_page_animate();", 6000);

	$(".allphoto").hover(function(){$(this).addClass("allphotoh");},function(){$(this).removeClass("allphotoh");});

	$(".section").mouseover(function() {$(this).addClass("poshover"); $("a", this).addClass("poswhite"); }).mouseout(function() {$(this).removeClass("poshover"); $("a", this).removeClass("poswhite"); });

	$(".naviPrevON, .naviNextON").mouseover(function() { $(".naviNextONE, .naviPrevONE", this).stop().animate({'opacity': 0 }); }).mouseout(function() { $(".naviNextONE, .naviPrevONE", this).stop().animate({'opacity': 1 }); });
	$("a.fancybox").fancybox({'overlayShow':true, 'overlayOpacity':0.73, 'padding':0, 'imageScale':true});

	//fontSize
	var cl = ".only_highlight"; var fSmin = 9; var fSmax = 15;
	var oFS = $(cl).css('font-size');
    $('.FontZ').click(function(){ $(cl).css('font-size', oFS); });
	$('.FontP').click(function(){ var size = parseInt($(cl).css('font-size')); if(size < fSmax) $(cl).css('font-size', (size+1)); });
	$('.FontM').click(function(){ var size = parseInt($(cl).css('font-size')); if(size > fSmin) $(cl).css('font-size', (size-1)); });

	$("a.bl_").attr({"target":"_blank"});

	$(".tags a").each(function() { $(this).css({'font-size':$(this).attr("rel")+"%" }).removeAttr("rel").attr({"href":public_root_path+"/search.html?tags="+$(this).attr("title")}).attr({"title":$(this).text()})   });
	
	if(jQuery.fn.pngFix) {
		$(document).not(".google").pngFix();
	};
	
	if(jQuery.fn.sifr) {
		$.sifr({path:'fonts'});
		$('.alexa').sifr({font:'alexa'});
		$('.myriad').sifr({font:'myriad'});
	};

	$(".gcms_loading").fadeOut("slow");
	$('.fileDescription').css('opacity', 0.7);
	$(cl).focus(function() { return false; }).noContext().rightClick(function() { return false; }).disableTextSelect();
	$('.add_comments').click(function() { $(this).hide(); $(".comments_fieldset").show("slow"); });
});

function main_page_animate() {
	if(portfolio_length > 1) {
		actual_slide = actual_slide + 1;
		if(actual_slide > portfolio_length) actual_slide = 1;
		$(".lastprojectimg, .nameproject, .detailproject").fadeOut(2000);
		$(".Lmenu_sp li").removeClass("current");
		$(".Lmenu_sp a").removeAttr("style");
		$(".Lmenu_sp a").each(function() { if($(this).attr("rel") == actual_slide) { 
			var el = $(this).parent();
			var offset = el.offset();
			var gloffset = $("#selected_project").offset();
			$(".back", el.parent()).animate({ left: offset.left-gloffset.left }, 600, "linear", function() { el.addClass("current") }); 
		} });
		$(".rel_"+actual_slide).fadeIn(2000);
		clearTimeout(timeout_slide);
		timeout_slide =	setTimeout("main_page_animate();", 6000);
	} else {
		clearTimeout(timeout_slide);
	}
}