var $j = jQuery.noConflict(); 
var ImageLoaded = 'img0';
var product_zoom;
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var is_ie = navigator.userAgent.toLowerCase().indexOf('msie') > -1;

$j(function(){
	
	/**********************************************
	************General styles jScript*************
	**********************************************/
	//add corners, but not for chrome
	if( !is_chrome ) {
		$j('.item, .rounded, .col-main, .block').corners();
	}
		
	//remove default input values	
	$j('#search').click(function() {
		if( $j(this).val() == 'search store' || $j(this).val() == 'search music' ) {
			$j(this).val('');
			//$j(this).css('color', '#585858');
		}
	});
	$j('#newsletter, #lp-newsletter-field').click(function() {
		if( $j(this).val() == 'Join Newsletter' || $j(this).val() == 'email address' ) {
			$j(this).val('');
			$j(this).css('color', '#585858');
		}
	});
	
	/**********************************************
	***********Shopping Cart Stuff*****************
	**********************************************/
	
	$j('.form-submit').click(function() {
		var formId = $j(this).attr('rel');
		$j('#'+formId).submit();
		return false;
	});
	
	/**********************************************
	*************Product Details jScript***********
	**********************************************/

	//used for item description / warranty info tabs in item details page
	$j('a.product-tab').not('a.link').click(function() {
		$j('a.product-tab').removeClass('active');
		$j(this).addClass('active');
		var element = $j(this).attr('rel');
		if( element == 'description' ) {
			$j('#item_description').removeClass('no-display');
			$j('#item_return_policy, #size_chart').addClass('no-display');
		} else if( element == 'return' ) {
			$j('#item_return_policy').removeClass('no-display');
			$j('#item_description, #size_chart').addClass('no-display');
		} else {
			$j('#size_chart').removeClass('no-display');
			$j('#item_return_policy, #item_description').addClass('no-display');
		}
		return false;
	});

	//zoom photo
	if( !$j('body').hasClass('category-music') ) {
		$j('#image').css('height','503px').css('width','346px');
	}
	    
	$j('a.detail-thumb').click(function() {
		$j('#vidPlayer,#big-image-box').hide().addClass('no-display');
		$j('#image-box,#loader-img,#zoom-button').show().removeClass('no-display');
		var ImageUrl = $j(this).attr('href');
		var ImageNumber = $j(this).attr('id');
    	if (ImageLoaded == ImageNumber) return false;
    	ImageLoaded = ImageNumber;
		new Effect.Fade('image', { duration: 0.25 });
    	NewImage = new Image();
    	NewImage.src = ImageUrl;
    	$j('#image').hide();
	   	NewImage.onload = function() {
	   		$j('#image').css('height','503px').css('width','346px').attr('src', NewImage.src);
		   	$j('#image').attr('src', NewImage.src);
	   		new Effect.Appear('image', { duration: 0.5, queue: 'end'});	
	   	}
		return false;
	});
	
	$j('a.music-thumb').click(function() {
		$j('#vidPlayer,#big-image-box').hide().addClass('no-display');
		$j('#image-box,#loader-img,#zoom-button').show().removeClass('no-display');
		var ImageUrl = $j(this).attr('href');
		var ImageNumber = $j(this).attr('id');
    	//if (ImageLoaded == ImageNumber) return false;
    	ImageLoaded = ImageNumber;
		//new Effect.Fade('image', { duration: 0.25 });
    	NewImage = new Image();
    	NewImage.src = ImageUrl;
    	$j('#image').addClass('no-display');
	   	NewImage.onload = function() {
	   		$j('#big-image').attr('src', NewImage.src);
	   		$j('#big-image-box').removeClass('no-display');
	   		if( NewImage.width > 700 ) {
	   			var width = 700;
	   			var snapWidth = NewImage.width - 700;
	   			snapWidth *= -1;
	   		} else {
	   			var width = NewImage.width;
	   			var snapWidth = 0;
	   		}
	   		$j('#big-image-box').css('width',width);
	   		if( NewImage.height > 400 ) {
	   			var snapHeight = NewImage.height - 400;
				snapHeight *= -1;	
				$j('#big-image-box').css('height','400px');
			} else {
				var snapHeight = 0;
				$j('#big-image-box').css('height',NewImage.height);
			}
				
			new Draggable('big-image', { 
					starteffect: false,
					endeffect: false,
	 			 	snap: function(x, y) {
	 			 		return[ 
            				(x < 0) ? (x > snapWidth ? x : snapWidth ) : 0,
                   			(y < 0) ? (y > (snapHeight) ? y : snapHeight) : 0 
          	         		];
    					} 
    		});
		   	
		   	$j('#loader-img').addClass('no-display').hide();
		   	$j('#big-image').css('top',0).css('left',0);
		   	new Effect.Appear('big-image-box', { duration: 0.5, queue: 'end'});		
	   	}
		return false;

	})
	
	$j('a#detail-movie-loader').click(function() {
		$j('#image-box,#big-image-box,#loader-img,#zoom-button').addClass('no-display').hide();
		$j('.product-shop,#vidPlayer').removeClass('no-display').show();
		return false;
	});

	$j('#image,#zoom-button').click(function() {
		$j('.product-shop').addClass('no-display');
		var ImageUrl = $j('#image').attr('src');
		$j('#big-image').attr('src', ImageUrl);
		$j('#big-image').css('top','0px');
		new Draggable('big-image', { 
						starteffect: false,
						endeffect: false,
						constraint: 'vertical',
	 				 	snap: function(x, y) {
	 				 		return[ 
            					(x < 0) ? (x > 0 ? x : 0 ) : 0,
                    			(y < 0) ? (y > (-628) ? y : -628) : 0 
                    		];
    					} 
    	});
		$j('#big-image-box').removeClass('no-display').show();
    	$j('#big-image').css('cursor','move');
	});
	
	$j('#image-box-close').click(function() {
		$j('.product-shop').removeClass('no-display');
		$j('#big-image-box').addClass('no-display').hide();
		if( $j('#image').hasClass('no-display') ) {
			$j('#image').removeClass('no-display');
		}
	})
	
	$j('#play-button').click(function() {
		if( $j(this).find('span').text() == 'Pause' ) {
			$j(this).find('span').text('Play');
		} else {
			$j(this).find('span').text('Pause');
		}
		//vidPlayer.playPauseVid();
		getFlashMovie('vidPlayer').enveControlVideo();
		//document.product_addtocart_form.vidPlayer.enveControlVideo();
	});
	
	//get the music sample player working
	$j('.music-sample').click(function() {
		var url = $j(this).attr('rel');
		
		$j('#musicPlayer').empty().html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="25" height="20" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" /><param name="autoplay" value="false" /><param name="movie" value="/skin/frontend/default/enve-me/media/ieMusicPreview.swf" /><param name="flashvars" value="src=' + url + '"></param><param name="quality" value="high" /><param name="bgcolor" value="#000" /><embed src="/skin/frontend/default/enve-me/media/ieMusicPreview.swf" quality="high" bgcolor="#000" width="25" height="20" name="musicPlayer" autoplay="true" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" flashVars="src=' + url + '" wmode="transparent" /></object>');
		
		return false;
	});
	
	//check all songs
	$j('#check-all').click(function() {
		if( !$j(this).attr('checked') ) {
			$j('.checkbox').attr('checked',false);
		} else { 
			$j('.checkbox').attr('checked',true);
		}
		reloadMusicPrice();
	});
	
	//add one song
	$j('input.downloadable-checkbox').click(function() {
		reloadMusicPrice();
	});
	
	//adjusts price on grouped music projects
	function reloadMusicPrice() {
		var total = 0.00;
		$j('input.downloadable-checkbox').each(function() {
			var price = ''; 
			price = $j(this).parent().find('.price').html().toString();
			price = price.substr(1);
			price = parseFloat(price);
			if( $j(this).is(':checked') ) {
				total += price;
			}
		});
		total = total.toFixed(2).toString();
		total = '$' + total;
		$j('#product-price-final').html(total);
	}
	
	//code for embed code in about us page
	$j('#link-html').click(function() {
		$j(this).select();
	});
	
	//show the page after the body is fully loaded
	$j('body').show();
	
	/*********************************************
	***************** Blog jScript ***************
	*********************************************/
	
	$j('#comment-submit').click(function(){
		$j('#commentform').submit();
		return false;
	});
	
	
});

//used to get the flash movie, different process for windows & mac
function getFlashMovie(movieName) {
	//return swfobject.getObjectById('vidPlayer');

  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}