////////////////// waerehouse link popup: ////////////////
$(function() {
  //DD-MM-YYYY
  $("#sm-warehouse").wrap('<a style="cursor: help;" href="javascript:couponpopupWindow(\'information_popup.php?info_id=120\')"></a>');

});
////////////////// waerehouse link popup/ ////////////////

////////////////// datepicker: ////////////////
$(function() {
  //DD-MM-YYYY
  $("input[name=delivery_date]").datepicker({dateFormat: "dd-mm-yy"});

});
////////////////// datepicker/ ////////////////

$(document).ready(function(){
  //$.tabs('container-1', 1);
  $.tabs('container-1');
  $("#pi-loader").hide();
});


////////////////// login form: ////////////////
$(document).ready(function(){

  $(".login-box-items input").focus(function() {
    $(this).parents().siblings('.login-box-items').css('opacity', 0.3).find('input').attr('disabled', 'disabled');
  }).blur(function(){
    $('.login-box-items').css('opacity', 1).find('input').removeAttr('disabled');
  });

  $("#login-box-singnin a").click(function(){
    $('#login-box .login-box-items').removeClass("login-box-hidden");
    $(this, '#login-box').parents('.login-box-items').addClass("login-box-hidden");
    //return false;
  });


  // set login for existing cutomers active depending of location hash 
  if(window.location.hash != '') {
    var hashpage = window.location.hash.split("#");
    //window.location.pathname = hashpage[1];
    if (hashpage[1] == 'login-box-returning') {
      $("#login-box-singnin a").click();
    }
  }

});
////////////////// login form/ ////////////////

////////////////// create_account form: ////////////////
function fill_address_manually () {
  $('.create-account-box-hidden').removeClass("create-account-box-hidden");
  $('#fill-address-manually').addClass("create-account-box-hidden");
}
$(document).ready(function(){
  $("#fill-address-manually a").click(function(){
    fill_address_manually();
    return false;
  });
});
////////////////// create_account form/ ////////////////

////////////////// wishlist: ////////////////
$(document).ready(function(){
var oldVal;
	$('.productListing input[@type=text]')
		.focus( function() {
			oldVal = $(this).attr('value');
		})
		.change( function() {
			$(this).parent().next().next().children().attr("checked", "checked");
	} );
});
////////////////// wishlist/ ////////////////

$(document).ready(function(){

////////////////// image thumbs: ////////////////
  var $oldSrc = $("#details-img0 img").attr("src");
  $("#details-img-thumbs img").hover(function(){
    $("#details-img0 img").attr("src", $(this).attr("src"));
  },function(){
    $("#details-img0 img").attr("src", $oldSrc);
  });
////////////////// image thumbs/ ////////////////


////////////////// room sets: ////////////////
  $("#section-3-link").click(function() {
    $("#pi-roomsetimg img").attr("src", $("#pi-roomsetthumbs img:first").attr("src"));
  });

  $("#pi-roomsetthumbs img").click( function() {
    $("#pi-roomsetimg img").attr("src", $(this).attr("src"));
  } );

////////////////// room sets/ ////////////////


////////////////// specification tips: ////////////////
  $("div.pl-productspecs img").hover(function(event){
    $specId = $(this).attr("src");
    $(this).after('<div id="pl-productspecstip"><img src="images/_specification/loader.gif" /></div>');

  	var tipOffset = {};
  	$("#pl-productspecstip").offset({ padding: true }, tipOffset);
  	var tipTopLeft = new Array();
  	$.each( tipOffset, function(i, n){
  		tipTopLeft[i] = n;
  	});
    var tipRightPos = (tipTopLeft['left'] + $("#pl-productspecstip").width());
  	var tipBottomPos = (tipTopLeft['top'] + $("#pl-productspecstip").height());

    targetImg = $(this);
    if (targetImg.attr('title')) {
      titleAttr = targetImg.attr('title');
      targetImg.attr('title','');
      $("#pl-productspecstip").html(titleAttr)
    	.css({
            //top: event.pageY,
    		top: ( $(window).height() < tipBottomPos ) ? event.pageY - $("#pl-productspecstip").height() - 200  : event.pageY,
            //left: event.pageX
    		left: ( $(window).width() < tipRightPos ) ? event.pageX - $("#pl-productspecstip").width() - 70  : event.pageX
      });

    } else {
      titleAttr = false;
      $("#pl-productspecstip")
      .load("specification.php?specid="+$specId)
    	.css({
            //top: event.pageY,
    		top: ( $(window).height() < tipBottomPos ) ? event.pageY - $("#pl-productspecstip").height() - 200  : event.pageY,
            //left: event.pageX
    		left: ( $(window).width() < tipRightPos ) ? event.pageX - $("#pl-productspecstip").width() - 70  : event.pageX
          })
          ;
    }

  },function(){
    $("#pl-productspecstip").remove();
    if (titleAttr) {
      targetImg.attr('title', titleAttr);
    }

  });

////////////////// specification tips/ ////////////////

////////////////// product benefits tips: ////////////////
$secondList = $("#pi-benefits-wrap ul.pi-benefitslist1");
if ($secondList.length) {
  $("#pi-benefits-wrap ul.pi-benefitslist0 li img").hover(function(event){

  $benefitId = $(this).attr("src");
  $(this).after('<div id="pi-productbenefitstip"><img src="images/_specification/loader.gif" /></div>');

	var tipOffset = {};
	$("#pi-productbenefitstip").offset({ padding: true }, tipOffset);
	var tipTopLeft = new Array();
	$.each( tipOffset, function(i, n){
		tipTopLeft[i] = n;
	});
  var tipRightPos = (tipTopLeft['left'] + $("#pi-productbenefitstip").width());


  targetImg = $(this);
  //&& targetImg.attr('title').length > 10
  if (targetImg.attr('title')) {
    titleAttr = targetImg.attr('title');
    targetImg.attr('title','');
    $("#pi-productbenefitstip").html(titleAttr);

  } else {
    titleAttr = false;
    $("#pi-productbenefitstip").css({
      top: event.pageY,
      //left: event.pageX
      left: ( $(window).width() < tipRightPos ) ? event.pageX - $("#pi-productbenefitstip").width() - 100  : event.pageX
    })
    .load("benefits.php?benefitid="+$benefitId)
    ;
  }


  },function(){
    $("#pi-productbenefitstip").remove();
    if (titleAttr) {
      targetImg.attr('title', titleAttr);
    }
  });
}
////////////////// product benefits tips/ ////////////////


});


//////////////////// tabs jquery plugin ////////////////////////////////////////////////////////////////////////////
$.tabs = function(containerId, start) {
    var ON_CLASS = 'on';
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:eq(' + i + ')').css({display:"block"});
    $(id + '>ul>li:nth-child(' + (i+1) + ')').addClass(ON_CLASS);
    $(id + '>ul>li>a').click(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);
            if (target.size() > 0) {
                $(id + '>div:visible').css({display:"none"});
                target.css({display:"block"});
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS);
            } else {
                alert('There is no such container.');
            }
        }
        return false;
    });
};


//////////////////// jquery.dimensions.pack.js
eval(function(p,a,c,k,e,r){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--)r[e(c)]=k[c]||e(c);k=[function(e){return r[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}('(5($){$.19={P:\'1.2\'};$.u([\'j\',\'w\'],5(i,d){$.q[\'O\'+d]=5(){p(!3[0])6;g a=d==\'j\'?\'s\':\'m\',e=d==\'j\'?\'D\':\'C\';6 3.B(\':y\')?3[0][\'L\'+d]:4(3,d.x())+4(3,\'n\'+a)+4(3,\'n\'+e)};$.q[\'I\'+d]=5(b){p(!3[0])6;g c=d==\'j\'?\'s\':\'m\',e=d==\'j\'?\'D\':\'C\';b=$.F({t:Z},b||{});g a=3.B(\':y\')?3[0][\'8\'+d]:4(3,d.x())+4(3,\'E\'+c+\'w\')+4(3,\'E\'+e+\'w\')+4(3,\'n\'+c)+4(3,\'n\'+e);6 a+(b.t?(4(3,\'t\'+c)+4(3,\'t\'+e)):0)}});$.u([\'m\',\'s\'],5(i,b){$.q[\'l\'+b]=5(a){p(!3[0])6;6 a!=W?3.u(5(){3==h||3==r?h.V(b==\'m\'?a:$(h)[\'U\'](),b==\'s\'?a:$(h)[\'T\']()):3[\'l\'+b]=a}):3[0]==h||3[0]==r?S[(b==\'m\'?\'R\':\'Q\')]||$.N&&r.M[\'l\'+b]||r.A[\'l\'+b]:3[0][\'l\'+b]}});$.q.F({z:5(){g a=0,f=0,o=3[0],8,9,7,v;p(o){7=3.7();8=3.8();9=7.8();8.f-=4(o,\'K\');8.k-=4(o,\'J\');9.f+=4(7,\'H\');9.k+=4(7,\'Y\');v={f:8.f-9.f,k:8.k-9.k}}6 v},7:5(){g a=3[0].7;G(a&&(!/^A|10$/i.16(a.15)&&$.14(a,\'z\')==\'13\'))a=a.7;6 $(a)}});5 4(a,b){6 12($.11(a.17?a[0]:a,b,18))||0}})(X);',62,72,'|||this|num|function|return|offsetParent|offset|parentOffset|||||borr|top|var|window||Height|left|scroll|Left|padding|elem|if|fn|document|Top|margin|each|results|Width|toLowerCase|visible|position|body|is|Right|Bottom|border|extend|while|borderTopWidth|outer|marginLeft|marginTop|client|documentElement|boxModel|inner|version|pageYOffset|pageXOffset|self|scrollTop|scrollLeft|scrollTo|undefined|jQuery|borderLeftWidth|false|html|curCSS|parseInt|static|css|tagName|test|jquery|true|dimensions'.split('|'),0,{}))

//////////////////// jquery.innerfade.js
eval(function(p,a,c,k,e,r){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--)r[e(c)]=k[c]||e(c);k=[function(e){return r[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}('(7($){$.N.9=7(g){O r.P(7(){$.9(r,g)})};$.9=7(m,g){e 2={\'n\':\'s\',\'h\':\'Q\',\'d\':\'f\',\'j\':R,\'D\':\'S\',\'E\':\'9\',\'k\':F};5(g)$.T(2,g);5(2.k===F)e 3=$(m).k();a e 3=$(m).k(2.k);5(3.8>1){$(m).o(\'G\',\'U\').o(\'V\',2.D).W(2.E);X(e i=0;i<3.8;i++){$(3[i]).o(\'z-Y\',Z(3.8-i)).o(\'G\',\'10\').11()};5(2.d=="f"){p(7(){$.9.l(3,2,1,0)},2.j);$(3[0]).t()}a 5(2.d=="b"){e 6=c.q(c.b()*(3.8));p(7(){12{4=c.q(c.b()*(3.8))}H(6==4);$.9.l(3,2,4,6)},2.j);$(3[6]).t()}a 5(2.d==\'u\'){2.d=\'f\';e 4=c.q(c.b()*(3.8));p(7(){$.9.l(3,2,(4+1)%3.8,4)},2.j);$(3[4]).t()}a{v(\'w-I x y A \\\'f\\\', \\\'b\\\' B \\\'u\\\'\')}}};$.9.l=7(3,2,4,6){5(2.n==\'J\'){$(3[6]).13(2.h);$(3[4]).14(2.h)}a 5(2.n==\'s\'){$(3[6]).15(2.h);$(3[4]).16(2.h,7(){K($(r)[0])})}a v(\'w-n x y A \\\'J\\\' B \\\'s\\\'\');5(2.d=="f"){5((4+1)<3.8){4=4+1;6=4-1}a{4=0;6=3.8-1}}a 5(2.d=="b"){6=4;H(4==6)4=c.q(c.b()*3.8)}a v(\'w-I x y A \\\'f\\\', \\\'b\\\' B \\\'u\\\'\');p((7(){$.9.l(3,2,4,6)}),2.j)}})(17);7 K(C){5(C.L.M){C.L.M(\'18\')}}',62,71,'||settings|elements|current|if|last|function|length|innerfade|else|random|Math|type|var|sequence|options|speed||timeout|children|next|container|animationtype|css|setTimeout|floor|this|fade|show|random_start|alert|Innerfade|must|either||be|or|element|containerheight|runningclass|null|position|while|Type|slide|removeFilter|style|removeAttribute|fn|return|each|normal|2000|auto|extend|relative|height|addClass|for|index|String|absolute|hide|do|slideUp|slideDown|fadeOut|fadeIn|jQuery|filter'.split('|'),0,{}))

//////////////////// rotator.js
$(document).ready(function(){
  $('#main-page-banners').innerfade({
    speed: 1500,
    timeout: 3000,
    containerheight: '140px'
  });
});

//////////////////// rollover.js
$(document).ready(function() {
    //make rollovers
    $("div.pl-productimg img.pl-thumb").hover(function(event) {
      $(this)
        .parents("div.pl-productimg")
        .find("img.pl-rollover")
        .css({
            position: "absolute",
            top: event.pageY,
            left: event.pageX,
            zIndex: 1000
            })
        .show();
    },function(){
      $(this).parents("div.pl-productimg").find("img.pl-rollover").hide();
    })
    .mousemove(function(event) {
      $(this).parents("div.pl-productimg").find("img.pl-rollover")
        .css({
    			  top: pos('Y') - 300 + 'px',
    			  left: pos('X') + 15 + 'px'
          });

		// get the current mouse position
      function pos(c) {
  			var p = c == 'X' ? 'Left' : 'Top';
  			return event['page' + c] || (event['client' + c] + (document.documentElement['scroll' + p] || document.body['scroll' + p])) || 0;
  		}
    });
});
