﻿var winWidth = 0;
var getLeft = 0;
var thisLeft = 0;
var thisAtId = 0;

$(document).ready(function() {

	$("#portfcats").css("display", "block");

	var aAdress = location.href;
	if (aAdress == "http://rodeopark.se/" || aAdress == "http://www.rodeopark.se/") {
		$("#pen").css("background", "none");
		$("#pen").flash({ src: '/Flash/start_flash.swf', width: 289, height: 140, wmode: 'transparent' });
	}

	var loadImages = new Array(4);
	var ix = 0;
	$(".case img").each(function() {
		loadImages[ix] = $(this).attr("src").replace(".jpg", "_.jpg");
		ix++;
	});

	//$.preloadImages(loadImages);

	//loadImages = loadImages.substr(0,parseInt(loadImages.length -1));
	//alert(loadImages);


	replaceChecks();

	//$("#portfcats input").change(function() { SetPortfCats(); });
	//$("#portfcats img").click(function() { SetPortfCats(); });

	$("form input[type='text']").focus(function() {
		if (this.value == this.defaultValue) this.value = "";
	});
	$("form input[type='text']").blur(function() {
		if (this.value == "") this.value = (this.defaultValue ? this.defaultValue : "");
	});

	getWinWidth();

	$(".jscontent").prepend("<div id=\"casebox\"><img src=\"/Images/Portfolio/horselink_start.jpg\" alt=\"\" /></div>");

	$(".jscontent").prepend('<div id="case1box"></div><div id="case2box"></div><div id="case3box"></div><div id="case4box"></div><div id="case5box"></div>');

	$("#case1box, #case2box, #case3box, #case4box, #case5box").css("opacity", "0.0");

	$("#case1box, #case2box, #case3box, #case4box, #case5box").hover(function() {
		$("#casebox").show();
		thisAtId = $(this).attr("id").replace("box", "");
		var toolText = $("#" + thisAtId).html().replace(".jpg", "_.jpg");
		$("#casebox").html(toolText);
	}, function() { $("#" + thisAtId).css("opacity", "1.00"); });

	$("#case1box, #case2box, #case3box, #case4box, #case5box").click(function() {
		thisAtId = $(this).attr("id").replace("box", "");
		var ScrollTo = $("#" + thisAtId).children("img").attr("alt");
		location.href = '/Portfolio/#' + ScrollTo;
	});

	$().mousemove(function(e) {
		getLeft = winWidth - 990;
		getNewLeft = getLeft / 2;
		thisLeft = Math.round(getNewLeft);
		thisNewLeft = (e.pageX - thisLeft) - 137;
		$("#casebox").css("left", thisNewLeft + "px");
		if (thisNewLeft < -130 || thisNewLeft > 830) {
			$("#casebox").hide();
		}
	});

	$(".jscontent").hover(function() { $(this).css("cursor", "ew-resize"); }, function() { $("#casebox").hide(); });



	$("body").prepend("<div id=\"currinfobox\"></div>");

	$(".wedid span").hover(function() {
		var toolText = "";

		if ($(this).attr("class") == "c") { toolText = "CMS Office"; }
		if ($(this).attr("class") == "w") { toolText = "Webb"; }
		if ($(this).attr("class") == "p") { toolText = "Print"; }
		if ($(this).attr("class") == "d") { toolText = "Design"; }
		if ($(this).attr("class") == "f") { toolText = "Front-end"; }
		if ($(this).attr("class") == "b") { toolText = "Back-end"; }
		if ($(this).attr("class") == "i") { toolText = "Identitet"; }

		$("#currinfobox").html(toolText);
		$("#currinfobox").show();
	}, function() { $("#currinfobox").hide(); });

	$().mousemove(function(e) {
		var thisTop = e.pageY - 50;
		var thisLeft = e.pageX - 10;
		$("#currinfobox").css("top", thisTop + "px");
		$("#currinfobox").css("left", thisLeft + "px");
	});



	$("a.lasmer, a.visahemsida, a.skicka").hover(function() {
		$(this).children("span.s1").fadeOut(400);
		$(this).children("span.s2").fadeIn(200);
	}, function() {
		$(this).children("span.s1").fadeIn(100);
		$(this).children("span.s2").fadeOut(300);
	});


	//$("a.lasmer").mouseout(function() { $(this).children("span.s2").fadeOut(); });

	SetPortf();

	$(".imgPortf div a, #imggalleri a").lightBox({
		overlayBgColor: '#1b1a15',
		overlayOpacity: '0.6'
	});

	$(".prfChange").click(function() {
		//221
		var thisId = $(this).attr("id").replace("prf", "");
		var thisImg = parseInt($(this).html());
		var i = 0;
		$("#prh" + thisId + " a img").each(function() {
			i++;
		});
		var newTop = 221 * (thisImg - 1);
		$("#prh" + thisId + " div").animate({ top: "-" + newTop + "px" }, 500, "swing");
	});
});



jQuery.preloadImages = function() {
	for (var i = 0; i < arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
}

$(window).bind("resize", function() {
	getWinWidth();
});

function getWinWidth() {
	if (jQuery.browser.msie) {
		winWidth = document.documentElement.offsetWidth;
	} else {
		winWidth = window.innerWidth;
	}
}


var ShowCats = "";
var NumCats = 0;
var checkNum = "|";
function SetPortfCats() {
	ShowCats = "";
	NumCats = 0;
	$("#portfcats input:checked").each(function() {
		ShowCats += $(this).val();
	});
	if (ShowCats.length > 0) {
		checkNum = "|";
		NumCats = ShowCats.split(checkNum).length - 1;
		ShowCats += "|"
	};
	PortfCats();
	
}
function PortfCats() {

	var CatHits = 0;
	if (NumCats > 0) {
		$(".wedid").each(function() {
			CatHits = 0;
			$(this).children("span").each(function() {
				thisClass = "|" + $(this).attr("class") + "|";

				if (parseInt(ShowCats.indexOf(thisClass)) >= 0) {
					CatHits++;
				}
			});
			if (CatHits == NumCats) {
				$(this).parents("li").fadeIn();
			} else {
				$(this).parents("li").fadeOut();
			}
		});
	} else {
		$("#content ul li").fadeIn();
	}
}


function SetPortf() {
	var x = 0;
	$(".imgPortf").each(function() {
		x++;
		$(this).attr("id", "prh" + x);
		var i = 0;
		$(this).children("div").children("a").children("img").each(function() {
			i++;
			$(this).parents("a").parents("div").parents(".imgPortf").next(".imgNums").html($(this).parents("a").parents("div").parents(".imgPortf").next(".imgNums").html() + "<span id=\"prf" + x + "\" class=\"prfChange\">" + i + "</span> ");
			$(this).parents("a").attr("rel","lightbox[prh" + x + "]")
		});
	});


	
}


sIFR.fromLocal = true;
sIFR.isEnabled = true;

var vag = {
	src: '/Flash/rockwell.swf'
};

sIFR.activate(vag);

//sIFR.replace(vag, {selector: 'h2,h3'});

sIFR.replace(vag, {
	selector: 'h2.toph2',
	wmode: 'transparent',
	css: ' .sIFR-root { font-size: 45px; color: #FFFFFF; text-align: left; }'
});

sIFR.replace(vag, {
	selector: 'h2',
	wmode: 'transparent',
	css: ' .sIFR-root { font-size: 20px; color: #FFFFFF; text-align: left; }'
});
 