// JavaScript Document
$(function(){
            if($.flash.available){
		//flash slide slideshow
		$('#homeslideshow').html(''); //clear alternative content
		$('#homeslideshow').flash({  
			swf: liveSite+'images/home_slideshow.swf',
			menu: "false",
			wmode: "transparent",
			width: "625",
			height: "250",
			flashvars: {
						clickTag: liveSite+'slideshow'
						}
		});
		
		//magazine flash viewer
		$('#magazine-flash-viewer').html(''); //clear alternative content
		$('#magazine-flash-viewer').flash({  
			swf: liveSite+'images/magazine.swf',
			menu: "false",
			wmode: "transparent",
			width: "890",
			height: "615",
			flashvars: {
						clickTag: liveSite,
						issue: window.magazineIssue
						}
		});
            }

            //Search box
            $('#searchFor').focus(function(){
                $(this).css('color','#000000');
                $(this).attr('value','');
            });

		//Controll the main menu drop down list
		$('ul li',$('#mainMenu')).hover(
			function(){$(this).addClass('over');},
			function(){$(this).removeClass('over');}
			);
		
		//Make the shipping details same as billing details
		$('#shippingController').click(function(){
			var theForm=document.forms['cart'];
			var billings = ['#bill_firstname','#bill_lastname','#bill_company','#bill_address', '#bill_address1', 
			                '#bill_city', '#bill_state', '#bill_postcode', '#bill_country','#bill_phone','#bill_email'];
			var deliveries = ['#delivery_firstname','#delivery_lastname','#delivery_company','#delivery_address', '#delivery_address1', 
			                  '#delivery_city', '#delivery_state', '#delivery_postcode', '#delivery_country','#delivery_phone','#delivery_email'];
			
			for( var i=0; i< billings.length; i++ )
			{
				if($('#shippingController').attr('checked'))
				{
					$(deliveries[i]).attr('value', $(billings[i]).attr('value'));
				}
			}
		});
		
		//Checkout confirm form
		$('#checkoutConfirmForm').submit(function(){
											if($('#terms-and-conditions').attr('checked')){
												return true;
											}else{
												alert('Please read and agree to the terms and conditions before the order can be submitted!');
												return false;
											}
										 });
		
		//User registration form verification
		$('#loginForm').submit(function(){
			if($('#member_pass').attr('value')!=$('#member_pass1').attr('value')){
				alert('Passwords entered are not the same!');
				return false;
			}
		});
		
		//product images lightbox
		$('#allImages a').lightBox();
		
		//Blog commment area
		$('.reply-button').click(function(){
											$('#cancel-reply').css('display','block');
											
											$('#parent_id').attr('value',$(this).attr('title'));
											$('#commentform-section').css('display','none');
											$(this).parent().append($('#commentform-section').remove());
											$('#commentform-section').slideDown('slow');
											
											$('#cancel-reply').click(function(){
																					$('#cancel-reply').css('display','none');
																					$('#parent_id').attr('value',0);
																					$('.comment-section').append($('#commentform-section').remove());
																					return false;
										   										});
											
											return false;
										  });
                                                                                  
       $('#col-right-inner').jScrollPane();
       
       $("#dj-list a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_rounded'});
});


//Animate the product detail slideshow images.
$(function(){
	var imagesUrl=Array();
	var mainImage=$('img').filter('#mainImage');
	var current=0;
	var interval=null;
	var intervalTime=5000;
	var thumbnailImages=$('img').filter('.thumbnail');
	
	thumbnailImages.each(function(i){
		var theSrc=this.src;
		var otherImagesUrl=Array();
		
		otherImagesUrl[0]=theSrc.replace(/thumb_/,'medium_');
		otherImagesUrl[1]=theSrc.replace(/thumb_/,'');
		imagesUrl[i]=otherImagesUrl;
		
		$(this).click( function(){
				clearInterval(interval);
				mainImage.attr('src',imagesUrl[i][0]).fadeIn();
				$('#theLink').attr('href',imagesUrl[i][1]);
				
				current=i;
				if(imagesUrl.length>1)//start slide show for over 1 image.
					interval=setInterval(slideShow,intervalTime);
				//The thumbnail class switcher
				thumbnailImages.each(function(i){
									if(i!=current)
										$(this).removeClass('thumbnail-over');
									else
										$(this).addClass('thumbnail-over');
								 });

			});
		
		$(this).mouseover( function(){
			if(current!=i)
				$(this).addClass('thumbnail-over');
			}
		);	

		$(this).mouseout( function(){
			if(current!=i)
				$(this).removeClass('thumbnail-over');
			}
		);	
	});

	function slideShow(){
			if(current<(imagesUrl.length-1))
				current++;
			else
				current=0; 
			
			mainImage.attr('src',imagesUrl[current][0]).fadeIn();
			$('#theLink').attr('href',imagesUrl[current][1]);
			
			thumbnailImages.each(function(i){
									if(i!=current)
										$(this).removeClass('thumbnail-over');
									else
										$(this).addClass('thumbnail-over');
								 });
			
		}
	
	
	$(thumbnailImages.get(0)).addClass('thumbnail-over');
	
	if(imagesUrl.length>1) //start slide show for over 1 image.
		interval=setInterval(slideShow, intervalTime);
});
