
$(function blurAnchors(){
    var a = $("a");
    for(var i = 0; i < a.length; i++){
        a[i].onfocus = function(){
            this.blur();
        };
    }
})

function dectectIE6 () {
    return $.browser.msie6 = ($.browser.msie && typeof(XMLHttpRequest) == "undefined" 
		&& /MSIE 6\.0/i.test(window.navigator.userAgent) 
		&& !/MSIE 7\.0/i.test(window.navigator.userAgent) 
		&& !/MSIE 8\.0/i.test(window.navigator.userAgent)
	);
}

function fixPngTransparency(elementID){
	// IF MSIE version 5 or 6
	if(navigator.userAgent.indexOf("MSIE 6") != -1 || navigator.userAgent.indexOf("MSIE 5") != -1){
		var pngImage 			= document.getElementById(elementID);
		var pngImageSrc			= pngImage.src;
		var spacerSrc			= 'images/spacer.gif'
		pngImage.src 			= spacerSrc;
		pngImage.style.filter 	= "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngImageSrc+"', sizingMethod='image')";
		$('#homebuttonImg').removeClass('roll_image');
	}
}

function getParam(param){
	var queryString = location.search;
	queryString 	= queryString.substr(1);
	var queryArr 	= queryString.split("&");
	
	for(i=0;i<queryArr.length;i++){
		var paramArr = queryArr[i].split("=");
		if (paramArr[0] == param){
			return paramArr[1];
		}
	}
	return "";
}

function getCookieValue(cookies, key) {
    var cookieArray = cookies.split(';');
    for (i in cookieArray){
        cookieArray[i] = cookieArray[i].replace(/^\s+|\s+$/g,"");
        var components = cookieArray[i].split('=');
        if (key == components[0]) {
            return components[1];
        }
    }
    return null;
}

function setCookie(name,value,expireDate){
    
    if (expireDate == '' || expireDate == null ){
        var expireDate = new Date();
        expireDate.setFullYear(expireDate.getFullYear() +1);
        expireDate.toGMTString();
    }
    
    document.cookie = name+'='+value+';expires='+expireDate+';';
}

function getProductSelectorOptions() {

    var userTypeOption = getCookieValue(document.cookie,"userType",'');
    var productTypeOption = getCookieValue(document.cookie,"productType",'');
    
    if (userTypeOption != null && productTypeOption != null){       
        if (userTypeOption != 'option6'){
            setFirstSelection(document.getElementById(userTypeOption));
            setSecondSelection(productTypeOption);
        }
    }
}

function getPDPTemplateVersion() {
    
    var templateVersion = getCookieValue(document.cookie, "templateVersion");
    var randomType = Math.round(Math.random());
    var expireDate = new Date();
    expireDate.setMonth(expireDate.getMonth() + 1);
    expireDate.toGMTString();
    
    if (templateVersion == null) {
        setCookie('templateVersion',randomType,expireDate);
        if (randomType == 0){
            document.location.href='minicafe_a.html';
        }
        if(randomType == 1){
           document.location.href='minicafe_b.html';
        }
    }
    else {
        if (templateVersion == 0){
            document.location.href='minicafe_a.html';
        }
        if (templateVersion == 1){
            document.location.href='minicafe_b.html';
        }
    }
}

/*function replaceTemplate() {
        
    //check if cookie is present
    var cookieCheck = document.cookie.indexOf('templateVersion=');
    
    //values for setting cookie
    var randomType = Math.round(Math.random());
    var expireDate = new Date();
    expireDate.setMonth(expireDate.getMonth() + 1);
    expireDate.toGMTString();
    
    //if no cookie present, set cookie with default value (0 or 1)
    if (cookieCheck == -1) {
        document.cookie = 'templateVersion=' + randomType + ';expires=' + expireDate + ';';
        if (randomType == 0){
            document.location.href='minicafe_a.html';
        }
        if(randomType == 1){
           document.location.href='minicafe_b.html';
        }
    }
    else {
        var cookieValue = document.cookie.toString();
        //filter the first contenttype
        cookieValue = cookieValue.split(';')[0];
        //filter the content value
        cookieValue = cookieValue.split('=')[1];

        if (cookieValue == 0){
            document.location.href='minicafe_b.html';
        }
        if (cookieValue == 1){
            document.location.href='minicafe_a.html';
        }
    }
}*/

/*rollover functionality. Add roll_image class to image*/
function roll_image() {
	$('img.roll_image').hover(function() {
			var imageSrc = $(this).attr("src");
			imageArr = imageSrc.split(".");
			var newImg = imageArr[0]+"_roll."+imageArr[1];
			$(this).attr("src", newImg);
		}, function() {
			var imageSrc = $(this).attr("src");
			imageArr = imageSrc.split(".");
			var newImageNamePart = imageArr[0].replace("_roll","");
			var newImg = newImageNamePart+"."+imageArr[1];
			$(this).attr("src",newImg);
	});
}

function roll_button() {
	$('.button')
		.hover(
			function() {
				$(this).addClass('button_roll');
			}, 
			function() {
				$(this).removeClass('button_roll');
			});
}

$(document).ready(function(){
	roll_image();
	roll_button();
});