function loadDefaultCss(cssPath){
    // create domain as per your hosting website.
	if(cssPath){
	    $.cookie("cssName", null, {'domain':''});
		$.cookie("cssName", cssPath, {'path':'/','domain':'.spinxwebdesign.com'}); // To create common cookies for all sub domains.
		//$.cookie("cssName", cssPath, {'path':'/'});
	} else {
	    $.cookie("cssName", null, {'domain':''});
		$.cookie("cssName", _siteRoot + 'style/white/colour.css', {'path':'/','domain':'.spinxwebdesign.com'}); //// To create common cookies for all sub domains.
		//$.cookie("cssName", _siteRoot + 'style/white/colour.css', {'path':'/'});
	}
    var link = $("#mainCSS");
    link.attr('media','all');
    if($.cookie("cssName") != null){
        link.attr('href', $.cookie("cssName"));
    }

	/*
	$.ajax({type: "GET", url: $.cookie("cssName"), cache: true, dataType: "css", success: function(msg){
            var link = $("#mainCSS");
            link.attr('media','all');
            link.attr('href', $.cookie("cssName"));
        }
    });
    */
}

function loadDefaultImages() {
	var css = $.cookie("cssName");
	if(!css){
	    css = _siteRoot + "style/black/colour.css"
	}
	var imagePath = css.replace(_siteRoot + 'style\/', _siteRoot + 'images/');
	imagePath = imagePath.replace(/colour.css/ig, '');
		
	for(var i=0; i < $(".changeimage").length; i++){
		var images = $(".changeimage")[i].src.split("/");
		$(".changeimage")[i].src = imagePath + images[images.length-1];
	}
	
	if(typeof(_thisHome) != 'undefined'){
	    var imgBG = setHomeBackground();
	    if(imgBG)
	        $('body').css({ backgroundImage : "url(" +imagePath + imgBG + ")", backgroundPosition:"top center", backgroundRepeat:"no-repeat" });
	}
	else{
	    $('body').css({ backgroundImage : "url(" +imagePath + "topbg-main-innerbg.jpg)", backgroundPosition:"top center", backgroundRepeat:"no-repeat" });
	}
	
	if(window.location.href.substring(0, 50).indexOf("spinxweb") < 0 && window.location.href.substring(0, 50).indexOf("localhost") < 0){
	    $('body').css({ backgroundPosition:"center 108" });
	}
	/*
	if(_siteRoot.toLowerCase() == window.location.href.replace(/#/,'').toLowerCase()){
	    var imgBG = setHomeBackground();
	    if(imgBG)
	        $('body').css({ backgroundImage : "url(" +imagePath + imgBG + ")", backgroundPosition:"top center", backgroundRepeat:"no-repeat" });
	} else{
	    // do coding for BG image
	}
	*/
	
	$('p.colors a').each(function(){
	    $(this).removeClass('on');
	    if(css.indexOf($(this).text()) > 0)
            $(this).addClass('on');
	});
}

$(function(){
	$('p.colors a').click(function(){
		loadDefaultCss(_siteRoot + 'style/' + this.id + '/colour.css');
		loadDefaultImages();
		return false;
	});
});

loadDefaultCss($.cookie("cssName"));
