// JavaScript Document

ddsmoothmenu.init({
	mainmenuid: "smoothmenu1", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

function nav() {
   var w = document.myform.mylist.selectedIndex;
   var url_add = document.myform.mylist.options[w].value;
   //alert(url_add);
   window.location.href = url_add;
}
   
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

defaultStatus="Great Life Labs";
function view(id)
{
  var link = "viewinvoice.php?id=" + id;
  window.open(link, "Invoice",
              "height=500,width=600,location=no,menubar=no,toolbar=no,scrollbars=yes");
}
	
function popNoPoints() 
{
  var link = "/nopoints.php";
  var options = "height=200,width=200,location=no,menubar=no,toolbar=no";
  var child = window.open(link,"Not Enough Points", options);
  child.opener = this;
}
function popCoupon() 
{
  var link = "/coupon/";
  var options = "height=200,width=250,location=no,menubar=no,toolbar=no";
  var child = window.open(link,"Coupon", options);
  child.opener = this;
}
function popEmailForm() 
{
  var link = "/mailinglist/";
  var options = "height=200,width=300,location=no,menubar=no,toolbar=no";
  var child = window.open(link,"Coupon", options);
  child.opener = this;
}
function pop(link)
{
  var options = "height=400,width=400,location=no,menubar=no,toolbar=no";
  var child = window.open(link,"Coupon", options);
  child.opener = this;
}

//$(document).ready(function(){
//$("#reg1").validate();
//});



$(document).ready(function() {
     $(".comment_button").click(function(){
          var element = $(this);
          var I = element.attr("id");
          $("#slidepanel"+I).slideToggle(300);
          $(this).toggleClass("active"); 
          return false;
     });
});

$(document).ready(function() {
     $("#reg1submit").click(function() {
          //alert("got here");
          username = $("#username").val();
          password = $("#password").val();
          //alert(username);
          var dataString = 'username='+username+'&password='+password;
          $.ajax({
               type: "POST",
               url: "/distribute/validate_username/",
               data: dataString,
               cache: false,
               success: function(html){  
                    html = $.trim(html); 
                    if (html == 'NG') {
                         alert("Login taken.  Please try another.");
                    } else {
                         window.location.href = '/distribute/distribute2/'+html;
                    }                  
                    
               },
               error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown + ' '+ textStatus);
               }
          });
          
          return false;
     });
}); 
     
$(document).ready(function() {
     $(".add_to_cart").click(function(){
          var element = $(this);
          var Id = element.attr("id");
          var qty = $("#qty"+Id).val();
          var code = $("#code"+Id).val();
          var currcat = $("#currcat"+Id).val();
          var brand_link = $("#brand_link"+Id).val();
          
          //alert(dataString);
          if(qty=='') {
               qty = 1;
          } 
          var dataString = 'qty='+ qty+'&code='+code+'&currcat='+currcat+'&brand_link='+brand_link;
          //alert(dataString);
          
          $.ajax({
               type: "POST",
               url: "cart/",
               data: dataString,
               cache: false,
               success: function(html){
                    //alert("html: " + html);
                    $(".cartsummary").replaceWith(html);
                    $("#"+Id).css("background-image", "url(/resources/images/buttons/add_to_cart_red.gif)");
                    setTimeout(function() {
                              $("#"+Id).css("background-image", "url(/resources/images/buttons/add_to_cart2.gif)");
                    }, 100);
                    $("#"+Id).val('Add Another');
               },
               error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown + ' '+ textStatus);
               }
          });
          
          /*
          $.ajax({
               type: "POST",
               url: "cart/slider",
               data: dataString,
               cache: false,
               success: function(html){
                    //alert(html);
                    $("#swrapper").replaceWith(html);
                    //$("#flash"+Id).hide();
               },
               error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown + ' '+ textStatus);
               }
          });
          */
          return false;
     });
});     

$('#animate-both').live( 'click', function () {
    $('#swrapper').each(function() {
		$(this).css('zIndex', 100000);
		$(this).css('position', 'absolute');
		$(this).css('right', 80);
		
	});

   $('#cartslide').animate({

       height: 'toggle',
       opacity: 'toggle'

    });
});

this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 150;  // vertical
		yOffset = 30;  // horizontal
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
	    
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
               .css("z-index",100000);
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
     
     
