﻿/* Queue the Site Load Events
===================================================================================== */
addLoadEvent(init);
addLoadEvent(initLabels);
//addLoadEvent(initSIFR);
addLoadEvent(initImages);
addLoadEvent(initMaps);


var $j = jQuery.noConflict();

function init() {
	$j("body").addClass("hasJs");
}

function initLabels() {
    $j(".moveLbls label").hide();

    $j(".moveLbls input:text").each(function() {
        setText($(this));
        $j(this).focus(function() { clearText($j(this)); });
        $j(this).blur(function() { setText($j(this)); });
    });

    $j(".moveLbls select").each(function() {
    setList($j(this));
    });

    $j(".moveLbls input:submit,.moveLbls input:image").click(function() {
    $j(".moveLbls input:text").each(function() { clearText($j(this)); });
    });


    function setText(txtBox) {
        if ($j(txtBox).val() == '') $j(txtBox).val($j(txtBox).siblings("label").text());
    }
    function clearText(txtBox) {
        var val = $j(txtBox).siblings("label").text();
        if ($j(txtBox).val() == val) $j(txtBox).attr('value', '');
    }

    function setList(list) {
        var val = $j(list).siblings("label").text();
        if ($j(list).find("option:first").val() != val) $j(list).find("option:first").text(val);
    }
}

//function initSIFR() {
//	sIFR.bAutoInit = false;
//  sIFR.setup();
//	
//	sIFR.replaceElement("headers", named({
//		sSelector:"div.content h1, div.content h2", 
//		sFlashSrc:"/scripts/sIFR/Myriad.swf", 
//		sColor:"#019934", 
//		sLinkColor:"#019934", 
//		nMarginTop:"20", 
//		nMarginBottom:"10",
//		sWmode:"transparent"
//	}));	
//}

/* product images
===================================================================================== */
var ori;
function initImages() {
	ori = $j(".product .images>img").attr("src");
	
	$j(".product .images div img").each(function(){
        $j(this).parent().hover(
					function(){
						var h = $j(this).attr("href");
            $j(".product .images>img").attr("src", h + ".thumb?w=246&h=246");
					},
					function(){
            $j(".product .images>img").attr("src", ori);					
					}
        );
    });
}



/* thickbox
===================================================================================== */
var tb_pathToImage = "/images/loadingAnimation.gif";
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('$j(c).3y(9(){1u(\'a.1j, 2R.1j, 3x.1j\');1r=1v 1y();1r.J=3A});9 1u(2t){$j(2t).o(9(){6 t=W.X||W.1N||L;6 a=W.p||W.2l;6 g=W.25||S;1e(t,a,g);W.2V();I S})}9 1e(E,d,14){2W{3(2u c.q.D.2y==="2z"){$j("q","19").n({v:"2k%",r:"2k%"});$j("19").n("2H","2Y");3(c.2e("1J")===L){$j("q").m("<Y 5=\'1J\'></Y><4 5=\'u\'></4><4 5=\'8\'></4>");$j("#u").o(C)}}b{3(c.2e("u")===L){$j("q").m("<4 5=\'u\'></4><4 5=\'8\'></4>");$j("#u").o(C)}}3(1Y()){$j("#u").2p("2Z")}b{$j("#u").2p("3B")}3(E===L){E=""}$j("q").m("<4 5=\'F\'><2j J=\'"+1r.J+"\' /></4>");$j(\'#F\').33();6 1b;3(d.K("?")!==-1){1b=d.34(0,d.K("?"))}b{1b=d}6 1L=/\\.1Z$|\\.2E$|\\.20$|\\.22$|\\.23$/;6 O=1b.1G().28(1L);3(O==\'.1Z\'||O==\'.2E\'||O==\'.20\'||O==\'.22\'||O==\'.23\'){1B="";1C="";Z="";1E="";1F="";T="";1A="";1D=S;3(14){B=$j("a[@25="+14+"]").36();2m(z=0;((z<B.1i)&&(T===""));z++){6 37=B[z].p.1G().28(1L);3(!(B[z].p==d)){3(1D){1E=B[z].X;1F=B[z].p;T="<1g 5=\'2o\'>&1c;&1c;<a p=\'#\'>38 &39;</a></1g>"}b{1B=B[z].X;1C=B[z].p;Z="<1g 5=\'2n\'>&1c;&1c;<a p=\'#\'>&3a; 3b</a></1g>"}}b{1D=1m;1A="1y "+(z+1)+" 3c "+(B.1i)}}}V=1v 1y();V.1l=9(){V.1l=L;6 1w=1X();6 x=1w[0]-2f;6 y=1w[1]-2f;6 l=V.r;6 f=V.v;3(l>x){f=f*(x/l);l=x;3(f>y){l=l*(y/f);f=y}}b 3(f>y){l=l*(y/f);f=y;3(l>x){f=f*(x/l);l=x}}11=l+30;1f=f+3f;$j("#8").m("<a p=\'\' 5=\'2q\' X=\'1O\'><2j 5=\'3g\' J=\'"+d+"\' r=\'"+l+"\' v=\'"+f+"\' 2l=\'"+E+"\'/></a>"+"<4 5=\'3h\'>"+E+"<4 5=\'3i\'>"+1A+Z+T+"</4></4><4 5=\'3j\'><a p=\'#\' 5=\'Q\' X=\'1O\'>1Q</a> 1R 1z 1o</4>");$j("#Q").o(C);3(!(Z==="")){9 13(){3($j(c).M("o",13)){$j(c).M("o",13)}$j("#8").s();$j("q").m("<4 5=\'8\'></4>");1e(1B,1C,14);I S}$j("#2n").o(13)}3(!(T==="")){9 1I(){$j("#8").s();$j("q").m("<4 5=\'8\'></4>");1e(1E,1F,14);I S}$j("#2o").o(1I)}c.1n=9(e){3(e==L){H=2a.2b}b{H=e.2c}3(H==27){C()}b 3(H==3m){3(!(T=="")){c.1n="";1I()}}b 3(H==3p){3(!(Z=="")){c.1n="";13()}}};15();$j("#F").s();$j("#2q").o(C);$j("#8").n({R:"P"})};V.J=d}b{6 2r=d.2F(/^[^\\?]+\\??/,\'\');6 G=2h(2r);11=(G[\'r\']*1)+30||3r;1f=(G[\'v\']*1)+3s||3t;U=11-30;N=1f-3v;3(d.K(\'1W\')!=-1){1M=d.1H(\'3w\');$j("#16").s();3(G[\'1K\']!="1m"){$j("#8").m("<4 5=\'2G\'><4 5=\'1p\'>"+E+"</4><4 5=\'2I\'><a p=\'#\' 5=\'Q\' X=\'1O\'>1Q</a> 1R 1z 1o</4></4><Y 2v=\'0\' 2w=\'0\' J=\'"+1M[0]+"\' 5=\'16\' 1N=\'16"+1k.2B(1k.1P()*2C)+"\' 1l=\'1x()\' D=\'r:"+(U+29)+"k;v:"+(N+17)+"k;\' > </Y>")}b{$j("#u").M();$j("#8").m("<Y 2v=\'0\' 2w=\'0\' J=\'"+1M[0]+"\' 5=\'16\' 1N=\'16"+1k.2B(1k.1P()*2C)+"\' 1l=\'1x()\' D=\'r:"+(U+29)+"k;v:"+(N+17)+"k;\'> </Y>")}}b{3($j("#8").n("R")!="P"){3(G[\'1K\']!="1m"){$j("#8").m("<4 5=\'2G\'><4 5=\'1p\'>"+E+"</4><4 5=\'2I\'><a p=\'#\' 5=\'Q\'>1Q</a> 1R 1z 1o</4></4><4 5=\'A\' D=\'r:"+U+"k;v:"+N+"k\'></4>")}b{$j("#u").M();$j("#8").m("<4 5=\'A\' 2L=\'2M\' D=\'r:"+U+"k;v:"+N+"k;\'></4>")}}b{$j("#A")[0].D.r=U+"k";$j("#A")[0].D.v=N+"k";$j("#A")[0].2O=0;$j("#1p").19(E)}}$j("#Q").o(C);3(d.K(\'2P\')!=-1){$j("#A").m($j(\'#\'+G[\'24\']).1V());$j("#8").2s(9(){$j(\'#\'+G[\'24\']).m($j("#A").1V())});15();$j("#F").s();$j("#8").n({R:"P"})}b 3(d.K(\'1W\')!=-1){15();3($j.1q.2S){$j("#F").s();$j("#8").n({R:"P"})}}b{$j("#A").2T(d+="&1P="+(1v 31().32()),9(){15();$j("#F").s();1u("#A a.1j");$j("#8").n({R:"P"})})}}3(!G[\'1K\']){c.2J=9(e){3(e==L){H=2a.2b}b{H=e.2c}3(H==27){C()}}}}3d(e){}}9 1x(){$j("#F").s();$j("#8").n({R:"P"})}9 C(){$j("#3k").M("o");$j("#Q").M("o");$j("#8").3l("3n",9(){$j(\'#8,#u,#1J\').3q("2s").M().s()});$j("#F").s();3(2u c.q.D.2y=="2z"){$j("q","19").n({v:"2D",r:"2D"});$j("19").n("2H","")}c.1n="";c.2J="";I S}9 15(){$j("#8").n({2N:\'-\'+26((11/2),10)+\'k\',r:11+\'k\'});3(!(1U.1q.2Q&&1U.1q.2U<7)){$j("#8").n({35:\'-\'+26((1f/2),10)+\'k\'})}}9 2h(1t){6 1h={};3(!1t){I 1h}6 1s=1t.1H(/[;&]/);2m(6 i=0;i<1s.1i;i++){6 18=1s[i].1H(\'=\');3(!18||18.1i!=2){3u}6 1S=2A(18[0]);6 1a=2A(18[1]);1a=1a.2F(/\\+/g,\' \');1h[1S]=1a}I 1h}9 1X(){6 12=c.2X;6 w=2K.2g||2d.2g||(12&&12.21)||c.q.21;6 h=2K.2i||2d.2i||(12&&12.2x)||c.q.2x;1T=[w,h];I 1T}9 1Y(){6 1d=3e.1d.1G();3(1d.K(\'3z\')!=-1&&1d.K(\'3o\')!=-1){I 1m}}',62,224,'|||if|div|id|var||TB_window|function||else|document|url||imageHeight|||||px|imageWidth|append|css|click|href|body|width|remove||TB_overlay|height||||TB_Counter|TB_ajaxContent|TB_TempArray|tb_remove|style|caption|TB_load|params|keycode|return|src|indexOf|null|unbind|ajaxContentH|urlType|block|TB_closeWindowButton|display|false|TB_NextHTML|ajaxContentW|imgPreloader|this|title|iframe|TB_PrevHTML||TB_WIDTH|de|goPrev|imageGroup|tb_position|TB_iframeContent||KeyVal|html|val|baseURL|nbsp|userAgent|tb_show|TB_HEIGHT|span|Params|length|thickbox|Math|onload|true|onkeydown|Key|TB_ajaxWindowTitle|browser|imgLoader|Pairs|query|tb_init|new|pagesize|tb_showIframe|Image|Esc|TB_imageCount|TB_PrevCaption|TB_PrevURL|TB_FoundURL|TB_NextCaption|TB_NextURL|toLowerCase|split|goNext|TB_HideSelect|modal|urlString|urlNoQuery|name|Close|random|close|or|key|arrayPageSize|jQuery|children|TB_iframe|tb_getPageSize|tb_detectMacXFF|jpg|png|clientWidth|gif|bmp|inlineId|rel|parseInt||match||event|keyCode|which|self|getElementById|150|innerWidth|tb_parseQuery|innerHeight|img|100|alt|for|TB_prev|TB_next|addClass|TB_ImageOff|queryString|unload|domChunk|typeof|frameborder|hspace|clientHeight|maxHeight|undefined|unescape|round|1000|auto|jpeg|replace|TB_title|overflow|TB_closeAjaxWindow|onkeyup|window|class|TB_modal|marginLeft|scrollTop|TB_inline|msie|area|safari|load|version|blur|try|documentElement|hidden|TB_overlayMacFFBGHack||Date|getTime|show|substr|marginTop|get|urlTypeTemp|Next|gt|lt|Prev|of|catch|navigator|60|TB_Image|TB_caption|TB_secondLine|TB_closeWindow|TB_imageOff|fadeOut|190|fast|firefox|188|trigger|630|40|440|continue|45|TB_|input|ready|mac|tb_pathToImage|TB_overlayBG'.split('|'),0,{}))



/* Googlemaps
===================================================================================== */
function initMaps() {
    if (!$j("div.map")[0]) return;

    var icon = createPushpin();

    if (GBrowserIsCompatible()) {
        $j("div.map").each(function() {
            var pos = new GLatLng($j(this).attr("lat"), $j(this).attr("lng"));
            var map = new GMap2(document.getElementById($j(this).attr("id")));
            map.setCenter(pos, 15);
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());
            map.addOverlay(new GMarker(pos, icon));
        });
    }

    $j("body").unload(GUnload);
}


var markers = new Array();
var map;
var info = new Array();
//function initMap() {
//    if (!$("#mapWrap")[0]) return;

//    var i = 0;
//    markers = new Array();
//    $("ul.mapData li").each(function(i) {
//        var ico = createPushpin();
//        var m = new GMarker(new GLatLng($(this).attr("lat"), $(this).attr("lng")), ico);
//        m.id = i;
//        markers.push(m);

//        var html = createInfoWin($(this).html());
//        info.push(html);

//    });

//    setTimeout("createMap();", 1000);
//    $("ul.mapData").remove();
//}

//function createMap() {
//    if (GBrowserIsCompatible()) {
//        map = new GMap2(document.getElementById("mapWrap"));
//        map.addControl(new GLargeMapControl());
//        map.clearOverlays();

//        //        if (markers.length > 0) {
//        //			map.setCenter(new GLatLng(markers[0].getPoint().lat(), markers[0].getPoint().lng()), 6);
//        //		} else {
//        map.setCenter(new GLatLng("53.956086", "-2.768555"), 5);
//        //        }
//        for (i = 0; i < markers.length; i++) {
//            map.addOverlay(markers[i]);
//            GEvent.addListener(markers[i], "click", function() {
//                this.openInfoWindowHtml(info[this.id]);
//            });
//        }
//        //zoomToMarkers();
//    }
//}
function createPushpin() {

    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);

    icon.infoWindowAnchor = new GPoint(9, 2);
    icon.infoShadowAnchor = new GPoint(18, 25);

    return icon;
}

function createInfoWin(tooltip) {
    var ret;

    ret = '<div class="infowin">';
    ret += tooltip
    ret += '</div>';

    return ret;
}
function zoomToMarkers() {
    var count = 0;
    var thePoint, x, y, minX, maxX, minY, maxY, span;

    for (i = 0; i < markers.length; i++) {
        marker = markers[i];

        thePoint = marker.getPoint();
        x = thePoint.lat(); y = thePoint.lng();
        if (count == 0) {
            minX = x; maxX = x; minY = y; maxY = y;
        }
        else {
            if (x < minX) minX = x;
            if (x > maxX) maxX = x;
            if (y < minY) minY = y;
            if (y > maxY) maxY = y;
        }
        count++;
    }

    if (count == 1)
        map.setCenter(new GLatLng(x, y), 12);
    else if (count > 1) {
        var center = new GLatLng((minX + maxX) / 2, (parseFloat(minY) + parseFloat(maxY)) / 2);
        span = new GSize(Math.abs(maxX - minX), Math.abs(maxY - minY));
        slopWid = 0;
        slopHgt = 0;
        deltaHgt = 0;
        var bounds = new GLatLngBounds(new GLatLng(minX - slopHgt, minY - slopWid), new GLatLng(maxX + slopHgt, maxY + slopWid)); // sw, ne
        var zoom = map.getBoundsZoomLevel(bounds);

        map.setCenter(center, zoom);
    }
}


