// Loading at startup 

$(document).ready(function(){
	hoverEffect();
	showBackpack();
	showDiv();
	historicalPic();
	extWindows();
});


// hoverEffects makes fancy effects when mouseover

function hoverEffect() {
	$(".main a, .kankar-start .top a, .header a, .kankar .top div a, .index a, .competition .right, .competition .left, .thanks78 a, .info .top a, .footer a, .photo-gallery a, .press .center a, .press .bottom a, .press3 .photoContent a").mouseover(function(){
		if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 7)
			$("img",this)[0].style.filter = $("img",this)[0].style.filter.replace(/.png/,".hover.png");
		else
			$("img",this).attr("src",$("img",this).attr("src").replace(/.png/,".hover.png"));
	});
		$(".main a, .kankar-start .top a, .header a, .kankar .top div a, .index a, .competition .right, .competition .left, .thanks78 a, .info .top a, .footer a, .photo-gallery a, .press .center a, .press .bottom a, .press3 .photoContent a").mouseout(function(){
		if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 7)
			$("img",this)[0].style.filter = $("img",this)[0].style.filter.replace(/.hover.png/,".png");
		else
			$("img",this).attr("src",$("img",this).attr("src").replace(/.hover.png/,".png"));
	});
}


// showPic displays the backpack in the color of the clicked color + the color name

function showBackpack(){
	$(".kankar .top div a").click(function(){
		var source = $(this).attr("href");
		$("#bigPic").attr("src",source);
		var color = $("img",this).attr("alt");
		$("#kankenColor").text(color);
		return false;
	});
}


// showDiv puts display:block on the hidden div

function showDiv(){
	$(".competition2 span").click(function(){
		$(".hiddenConditions").addClass("show");
	});
}

// historicalPic displays the photo of the clicked year and makes the active year bold

function historicalPic(){
	$(".info.historical .bottom li").click(function(){
		if ($("a",this).attr("href").search(/_/)!=-1) {
			$("#historicalPhoto").removeClass("vertical");
			$("#historicalPhoto").addClass("horizontal");		
		}
		else {
			$("#historicalPhoto").addClass("vertical");
			$("#historicalPhoto").removeClass("horizontal");		
		}
		$("#historicalPhoto").attr("src",$("a",this).attr("href"))
		$(".info.historical .bottom li").removeClass("activeHistory")
		$(this).addClass("activeHistory");
		return false;
	});

}


// extWindows() makes links open in a different window. use rel="external" instead of target="_blank" and rel="popup" or rel="popup|[width]|[height]" for popups

function extWindows(){
	$("a[rel=external]").attr("target","_blank");
	$("a[rel^=popup]").click(function(){
		theHref = $(this).attr("href");
		$(this).attr("href","javascript:void(0)");
		var popupWidth, popupHeight
		var relSplit = $(this).attr("rel").split("|");
		if(relSplit[1]){
			popupWidth = relSplit[1];
			popupHeight = relSplit[2];
		} else {
			popupWidth = 435;
			popupHeight = 350;
		}
		popMeUp(theHref,popupWidth,popupHeight)
	});
	
}
function popMeUp(strURL, strWidth, strHeight) {
    theWin = window.open(strURL, "popupWin", "scrollbars,resizable,height=" + strHeight + ",width=" + strWidth);
    theWin.focus();
}
