// JavaScript Document
// (c) Thinkcyber.com

var valume = '';
//var currentVolume = -1
/*
var myFlash = "";
myFlash = $.flash({   swf: 'player.swf',
					width: 290,
					height: 24,
					flashvars: { soundFile: "/marinakamen/includes/mp3/1.mp3,/marinakamen/includes/mp3/2.mp3,/marinakamen/includes/mp3/3.mp3",titles: "Walk On,You are Everything,Last Christmas",artists:"U2,Mary J. Blye,George Michael",autostart: "no", text: '0xE40D8A' }  });

*/


$.fn.showIf = function( show, arg ) {
   return this[ show ? 'show' : 'hide' ]( arg );

};

			jQuery(document).ready(function() {
				
				/*
					$(function() {
					$('#pane1')
					.jScrollPane(
						{
							showArrows:true
						}
					);
					});
				*/

				//$('#pane1').jScrollPane({showArrows:true});
				//$('#audioplayer_1').html(myFlash);
				$('#songtitle').hide();
				$('#click_play').hide();
				$('#buyf').hide();
				$('#buyf1').hide();
				$('#buyf2').hide();
				$('#itunes').hide();
				$('.click_on_each').fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800).fadeOut(800).fadeIn(800);




				listensound = function(id,pt,subcat,mp3,artist,title,myImage,myPrice,myPrice1,myPrice2,itunes){
				//alert("MP3 File" +mp3)
					$('#click_play').hide();
					function convertQuotes(string){
							return string.replace(/##/g,"'");
							return string.replace(/###/g,"\"");
							return string.replace(/%%/g,"(");
							return string.replace(/%%%/g,")");
					}
					 
					var myImageindex = (myImage.indexOf(".jpg"));
					//alert("Hello " + myImageindex);
					var titlenew = '';
					titlenew = convertQuotes(title);
					var mp3new = convertQuotes(mp3);
					
					
					var agent=navigator.userAgent.toLowerCase();
					var is_iphone = (agent.indexOf('iphone')!=-1);
					if (is_iphone) {
						//$('#audioplayer_1').html(mp3);
						//ajaxify(mp3);
						/*$.ajax({
						  url: mp3,
						  cache: false,
						  async: false
						});*/
						//$().jOverlay({url: mp3});
						var mymp3= '<object type="audio/x-mpeg" data="http://www.marinaonline.com/fitnesscenter/treadmill_mp3s/16_Treadmill/16_Treadmill_S.mp3" width="200" height="20"><param name="controller" value="true" /><param name="autoplay" value="false" /><param name="autostart" value="0" /></object>';
						$('#audioplayer_1').html(mymp3);

					} else {
					
					
					
					$('#audioplayer_1')
					
					.flash({   swf: 'player.swf',
										width: 290,
										height: 24,
										flashvars: { soundFile: mp3, artists: artist, titles: titlenew, autostart: 'yes', text: '0xE40D8A' }
						  });
					
					}
					//var myImageindex = (myImage.indexOf(".gif"));
					
					var myImag = myImage;
					
					if (myImag != "") {
						if (myImageindex > 0) {
						
						var myImagecover = '<img src="/marinakamen/audioimages/' + myImag + '" width="130" height="130" border="0" alt="" />';
						//alert(+myImage+);
						} else {
						
							var myImagesrc = "<img src='/marinakamen/images/icons/icon130/";
							var myImagesrc1 = ".gif' width='130' height='130' border='0'>";
							var myImagecover = myImagesrc + subcat + myImagesrc1;
						}
					//alert("Image File " +myImagecover)
					
					var myitunes = itunes;
					//alert("My Itunes " +myitunes)
					if (myitunes != "") {
						
							var base = '<a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?id=';
							var base1 = '&amp;s=143441" title="Get it now in iTunes" target="_blank"><img src="images/itunes_111_18.gif" id="itunesimg" height="18" vspace="2" width="111" alt="Get it now in iTunes" border="0" /></a>';
							var dispitune = base + myitunes + base1;
					$('#itunes').html(dispitune);
					$('#itunes').show();
					} else {
						$('#itunes').hide();
					}
					$('#coverholder').html(myImagecover);
					$('#songtitle').html(titlenew);
					$('#songtitle').show();
					
					$('#buyf').show();
					$('#buyf1').hide();
					$('#buyf2').hide();
					$('#myfreedownload').hide();

					$('#myPrice').html("$" + myPrice);
					$('.product_id').val(id);
					$('.product_type').val(pt);
					$('.product_subtype').val(subcat);
					$('.product_downloadonly').val(myitunes);
					
					
					var nav=navigator.appVersion.toLowerCase();
					var is_mac = (nav.indexOf("mac")!=-1);
					if (is_mac) {
							var mysavelink = "Download Linked File As..";
						} else {
							var mysavelink = "Save Target As..";
					}

					var myfreebegin = '<a class="help" href="';
					var myfreebegin1 = '" title="Right Click. A pop up window will appear. Choose the &quot;' + mysavelink + '&quot; option. Title: ';
					var myfreeend = '" target="_blank"><span class="pricebutton">Free Download</span> &nbsp;<img src="/marinakamen/images/icons/download_g_17_15.gif" width="19" height="17" border="0" align="bottom" /></a>';
					var myfreetotal = myfreebegin + mp3new + myfreebegin1 + titlenew + myfreeend;


					
					if(myPrice1 != ""){
							if((myPrice1 == "0") || (myPrice1 == "0.00")) {
								$('#myfreedownload').html(myfreetotal);
								$('#myfreedownload').show();
								$('#buyf1').hide();
							} else {
								$('#myPrice1').html("$" + myPrice1);
								$('#buyf1').show();
							}
					}

					if(myPrice2 != ""){
						$('#myPrice2').html("$" + myPrice2);
						$('#buyf2').show();
					}
					
					switch(pt)
						{
						case "1":
							var fileid = "/marinakamen/marina_video01.php?id="+id;
							break;
						case "2":
							var fileid = "/marinakamen/marina_video02.php?id="+id;
							break;
						case "3":
							var fileid = "/marinakamen/marina_video03.php?id="+id;
							break;
						case "4":
							var fileid = "/marinakamen/marina_video04.php?id="+id;
							break;
						default:
							var fileid = "/marinakamen/marina_video01.php?id="+id;
							break;
						}

					$("#loading").html('<p><img src="images/ajax-loader.gif" width="100" height="19" alt="Please wait.." /></p>');
					
					ajaxify(fileid);
					}
					//<img src="audiocdimages/pro_7.jpg" width="90" height="90" class="field" border="0">
				
				
				}
				
				//@ ajax function get page content
				function ajaxify(file){
						//@ loading message
						//$('<div id="loading"></div>').html("Loading Content: "+file+" ...").appendTo('#wrapper').fadeIn();
						//$("#loading").html('<p><img src="images/ajax-loader.gif" width="100" height="19" alt="Please wait.." /></p>');
						//@ http GET request
						
						$.get(file,function(data) {
							//@ add data to wrapper div, fade it slowly
							
							$("#wrapper").slideDown('slow',function(){
								$(this).html(data).fadeIn('slow',function(){
									$('#loading').fadeOut('slow',function(){$(this).remove();});
								});
							});
						});
					}
				$(".stripeMe>tbody>tr")
					   //.not(":first,:last")
				
				.hover( function() {
				$(this).addClass("over");
					   },function() {
						   $(this).removeClass("over");
					   })
				.click( function(e) {
					$(this).addClass('highlight');
					$(this).removeClass("alt");
					   //alert("Amount: " + $(this).find("td:nth-child(4)").text());
				})
				.filter(":even")
				.addClass("alt");
	
				//$("a[@rel]").click(function() {
				
				//$("#container_shop").load("http://www.marinaonline.com/marinakamen/cart_output.php", {thread_count: this.rel});
				
				//return false; ?product_id=201&product_type=4&without=Buy
				
				//});
				$(".buyform").submit(function() {
				var product_idval = $(".product_id:eq(0)").val();
				var ptval = $(".product_type:eq(0)").val();
				var psubval = $(".product_subtype:eq(0)").val();
				var downloadval = $("#product_downloadonly").val();
				var withoutval = "with";
				//alert("Buyform " +withoutval);
				$.get("add_product.php", { product_id: product_idval, 
				product_type: ptval, withone: withoutval, product_subtype: psubval, product_downloadonly: downloadval}, function(data) {
				//alert("Amount: " + product_idval)
					$("#container_shop").html(data);
					});
				return false;
				});
	
				$(".buyform1").submit(function() {
				var product_idval = $(".product_id:eq(1)").val();
				var ptval = $(".product_type:eq(1)").val();
				var psubval = $(".product_subtype:eq(1)").val();
				//var downloadval = $(".product_downloadonly:eq(1)").val();
				var withoutval = "without";
				//alert("buyform1 " +withoutval);
				$.get("add_product.php", { product_id: product_idval, 
				product_type: ptval, without: withoutval, product_subtype: psubval}, function(data) {
				//alert("Amount: " + product_idval)
					$("#container_shop").html(data);
					});
				return false;
				});
	
				$(".buyform2").submit(function() {
				var product_idval = $(".product_id:eq(2)").val();
				var ptval = $(".product_type:eq(2)").val();
				var psubval = $(".product_subtype:eq(2)").val();
				var withoutval = "both";
				//alert("buyform2 " +withoutval);
				$.get("add_product.php", { product_id: product_idval, 
				product_type: ptval, both: withoutval, product_subtype: psubval}, function(data) {
				//alert("Amount: " + product_idval)
					$("#container_shop").html(data);
					});
				return false;
				});
	
				function buynow(file){
						//@ loading message
						//$('<div id="loading"></div>').html("Loading Content: "+file+" ...").appendTo('body').fadeIn();
						//@ http GET request
						$.get(file,function(data) {	
							//@ add data to wrapper div, fade it slowly
							$("#wrapper").slideUp('slow',function(){
								$(this).html(data).slideDown('slow',function(){
									$('#loading').fadeOut('slow',function(){$(this).remove();});
								});
							});
						});
					}
				/*function example_ajax_request() {
					$('#example-placeholder').html('<p><img src="/images/ajax-loader.gif" width="220" height="19" /></p>');
					$('#example-placeholder').load("/examples/ajax-loaded.html");
				}
				
				$("#clickme").click( function() {
							  $('#example-placeholder').html('<p><img src="images/ajax-loader.gif" width="220" height="19" /></p>');
							  setTimeout('example_ajax_request_go()', 2000);

							function example_ajax_request_go() {
							  $('#example-placeholder').html('<p>We are done.</p>');
							}
				});
				
				
							$("#bill_to_co").is(":checked") 
				$("#shipping_fieldset input, #shipping_fieldset select").each(function() {
				    var elem = $(this);
				    $("#billing_fieldset #"+ 
				        elem.attr("id").replace(/shipping/, "billing")).val(elem.val());
				});

				*/
					
				
				jQuery.validator.addMethod("billingRequired", function(value, element) {
						if ($("#bill_to_co").is(":checked"))
							return $(element).parents("#billing_fields").length;
						return !this.optional(element);
				}, "");
				
				  // toggle optional billing address
				  var subTableDiv = $("div.subTableDiv");
				  var toggleCheck = $("input.toggleCheck");
				  toggleCheck.is(":checked")
					? subTableDiv.hide()
					: subTableDiv.show();
				  $("input.toggleCheck").click(function() {
					  if (this.checked == true) {
						subTableDiv.slideUp("medium");
						$("form").valid();
					  } else {
						subTableDiv.slideDown("medium");
					  }
				  });
	
				
				    //when the checkbox is checked or unchecked
				$('#copyaddress').click(function() {
						
					// If checked
					if ($("#copyaddress").is(":checked")) {
						
						//for each input field
						$('#shipping_fields input', ':visible', document.body).each(function(i) { 
							//copy the values from the billing_fields inputs
							//to the equiv inputs on the shipping_fields
							$(this).val( $('#billing_fields input').eq(i).val() );
							});
						//won't work on drop downs, so get those values
						var bcountry = $("#bcountry").val();
						
									  if (bcountry == 'US' || bcountry == 'CA') {
											$("#country").selectOptions(bcountry);
											var bstate = $("#bstatedrop").val();
											$("#sstatedrop").selectOptions(bstate);
											$("#sstateinput").val(bstate);
											//$("#addressform").validate();

									} else {
											$("#scountry").selectOptions(bcountry);
											$('#sstateinput').val(bstate);
											$("#sstatedrop").selectOptions(bstate);
											$('#sstateinput').show();
											$('#sstatedrop').hide();

									  }
						
						
					} else {
				
						//for each input field
						$('#shipping_fields input', ':visible', document.body).each(function(i) { 
							//set shipping_fields inputs to blank
							$(this).val(""); 
							});
						$("#scountry").selectOptions("");
						$("#sstatedrop").selectOptions("");
					}
				});

				$("#myaccountform").validate();
				$("#addressform").validate();
				
				//$("#creditcardform").validate();
				$("#addressform").submit(function() {
				
											// If checked
						if ($("#bill_to_co").is(":checked")) {
							
							//for each input field
							$('#shipping_fields input', ':visible', document.body).each(function(i) { 
								//copy the values from the billing_fields inputs
								//to the equiv inputs on the shipping_fields
								$(this).val( $('#billing_fields input').eq(i).val() );
								});
							//won't work on drop downs, so get those values
							var bcountry = $("#bcountry").val();
							
										  if (bcountry == 'US' || bcountry == 'CA') {
												$("#country").selectOptions(bcountry);
												var bstate = $("#bstatedrop").val();
												$("#sstatedrop").selectOptions(bstate);
												$("#sstateinput").val(bstate);
												//$("#addressform").validate();
	
										} else {
											$("#scountry").selectOptions(bcountry);
											$('#sstateinput').val(bstate);
											$("#sstatedrop").selectOptions(bstate);
											$('#sstateinput').show();
											$('#sstatedrop').hide();
											
											
										  }
							
						return true;
						} 
						
				 });
				
				 $(function() {
					$("#creditcardform").validate({
						rules: {
							credit_num: {
								creditcard2: function(){ return $('#cc_type').val(); }
							}
						}		
					});
			
			
					// helper function to fire validation on field2 when cardType changes
					//
					$('#cc_type').change(function(){
						$("#creditcardform").validate().element('#credit_num');
					});
				});
				
				
				/*
				$('.leaser').each(function (){
					var name = $(this).attr('name');
					
					if ($(this).val()!='other') {
						$(this).next().removeAttr('name').hide();
						
						
						}
				});*/
				
				$('#howdidyou').change(onChange);
				$('#howdidyou_input').hide();
				function onChange() {
					var desiredName = $(this).attr('name');
					if ($('#'+desiredName).val()=='other') {
						$("#howdidyou_input").show();
						$("#howdidyou").hide();
					} else {
						$("#howdidyou").show();
					    //$("#howdidyou").val(desiredName);
					}
				}
				
				/*
				var myCountry = $("input[name='bcountry']").getValue();
				if myCountry == "US";{
					$("#bstatedrop").show();
				} else {
					$("#bstateinput").hide();
				}
				*/
				
				$('#bcountry').change(function(){
				
				   var myvalue = $(this).val();
				   
				  if (myvalue == 'US' || myvalue == 'CA') {
					$('#bstatedrop').show();
					$('#bstateinput').hide();
			  	} else {
					$('#bstatedrop').hide();
					$('#bstateinput').show();
					
				  }
				
				});

				
				$('#scountry').change(function(){
				
				   var mysvalue = $(this).val();
				   
				  if (mysvalue == 'US' || mysvalue == 'CA')  {
					$('#sstatedrop').show();
					$('#sstateinput').hide();
				  } else {
					$('#sstatedrop').hide();
					$('#sstateinput').show();
					
				  }
				
				});
				
				$('<div id="overlay"/>').css({
					position: 'fixed',
					top: 0,
					left: 0,
					width: '100%',
					height: $(window).height() + 'px',
					background: 'url(/marinakamen/images/ajax-loader_new.gif) no-repeat center'
				}).hide().appendTo('body');


				// Assign click function:
				$('#zzz_creditcardform').click(function(){
					// SHOW overlay
					$('#overlay').show();
					// Retrieve data:
					//$('#overlay').hide();
					
					// Prevent default action of link:
					return true;
				});
				//View Cart
				//$('#view_cart').load("cart_big.php");
	
	

	});	