function URLencode(sStr) {
    return escape(sStr)
        .replace(/\+/g, '%2B')
        .replace(/\"/g,'%22')
        .replace(/\'/g, '%27')
}

$(document).ready(function() {
	// home
	$(".homeFeature").click(function() {
		window.location = $("h3 a",this).attr("href");
	});
	$(".homeFeature").mouseover(function() {
		$(this).css("background-position","0 -144px");
		$(this).css("cursor","pointer");
	});
	$(".homeFeature").mouseout(function() {
		$(this).css("background-position","0 0");
		$(this).css("cursor","pointer");
	});

	
	//category
	$(".range, .product, .relatedProduct , .basketProduct").click(function() {
		window.location = $("a",this).attr("href");
	});
	$(".range, .product, .relatedProduct, .basketProduct").mouseover(function() {
		$(this).css("cursor","pointer");
	});
	$(".rightFeature").click(function() {
		window.location = $("h3 a",this).attr("href");
	});
	$(".rightFeature").mouseover(function() {
		$(this).css("background-position","0 -144px");
		$(this).css("cursor","pointer");
	});
	$(".rightFeature").mouseout(function() {
		$(this).css("background-position","0 0");
		$(this).css("cursor","pointer");
	});
	
	/* Products */
	$(".btn").mouseover(function() {
		if($.browser.msie) {
			$(this).css("opacity",".8");
		}			
	});
	$(".btn").mouseout(function() {
		if($.browser.msie) {
			$(this).css("opacity","1");
		}	
	});
	$("#productLarge").prepend('<a href="sdf" class="back">Back</a>').css("display","none");
	
	$("#productImg").click(function() {
		$(".productCol1,.productCol2").fadeOut("slow",function() {$("#productLarge").fadeIn("slow").css("cursor","pointer")});
		return false;
	});
	$("#productLarge").click(function() {
		$("#productLarge").slideUp("slow",function() {$(".productCol1,.productCol2").fadeIn("slow")});
		return false;
	});
	
	/* News */
	$("a.bigBtn").mouseover(function() {
		$(this).css("cursor","pointer");
		if(!$.browser.msie || $.browser.version != "6.0") {
        $(this).css("opacity",".8");		
		}
	});
	$("a.bigBtn").mouseout(function() {
		if(!$.browser.msie || $.browser.version != "6.0") {
        $(this).css("opacity",".9999");	
		}	
	});
	
	/* Headings */
	if(document.getElementById("pageTitle")) {
	if(!$.browser.msie || $.browser.version != "5.5") {
		txt = escape($("#content h2").html());
		var so = new SWFObject("/site_media/swf/h2.swf?txt="+txt, "h2", "800", "25", "8", "#ffffff");
		so.addParam("wmode", "transparent");
		so.write("pageTitle");
	}
	}

    /* Distributors */
    initial_values = []
    $('input, select, textarea').each(function(){
        initial_values[this.id] = this.value
    })
    $('#id_postcode').focus(function() {
        this.select()
    })
    $('#find_form').submit(function(){
        data = $('#find_form').serialize();
        $('#results').html('searching ......')
        $.ajax({
            url:"/distributors/find/",
            type:'POST',
            data:data,
            success:function (msg){
                $('#results').hide()
                $('#results').html(msg)	
                $('#results').slideDown()
            }
        })
        return false;
    })

	if($('#contact_form').length == 0)  // the contact page as an element with the same id!
	{
      $('#id_country').change(function (){
        var c = $('#id_country').attr('value')
        if(c != '' && c !=undefined)
            window.location = '/distributors/international/' + c
      })
	}

    //$('div.title_crumb').hide().fadeIn(500);

});

document.write('<style type="text/css"> .hide { display:none; } </style>'); 

