		// IE8 Fix for indexOf() thanks to http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/
		if(!Array.indexOf){
			Array.prototype.indexOf = function(obj){
				for(var i=0; i<this.length; i++){
					if(this[i]==obj){
						return i;
					}
				}
				return -1;
			}
		}

		function triggerAjax(elt){
			$.get(elt.attr('href'), null, function( data, status ){
				if( data.success == true )
				{
					if( data.callback != undefined )
					{
						if( data.callback == 'loadCart' )
						{
							loadCart();
						}
					}
				}
			}, "json");
		}
		
		function loadCart()
		{
			$("#listcart").fadeOut();
			$("#cartdrop").load(url_loadcart, null, function(){
				$("#listcart").fadeIn();
				applyTriggerAjax("#cartdrop");
				
				if( isLoggedIn == 0 )
				{
					userOnlyTips("#cartdrop");
				}
			});
		}

		var curSkin = 0;
		var curPage = 1;
		
		function loadSkinTab( /*id,*/ page )
		{
			/*if( curSkin != id )
			{
				curPage = 1;
				curSkin = id;
			}*/
			
			if( page == undefined )
			{
				page = curPage;
			}
			
			$("#skinsPlaceholder").slideUp();
			$("#skinsPlaceholder").load(url_homeskin + 'page=' + page, null, function(){
				//$(".skintab").removeClass("active");
				//$("#category" + id).addClass("active");
				largerThumbnailPreview();
				$("#skinsPlaceholder").slideDown();
			});
		}
		
		function nextPageSkinTab()
		{
			curPage += 1;
			
			loadSkinTab(curPage);
		}
		
		function prevPageSkinTab()
		{
			if( curPage == 1 )
			{
				return;
			}
			
			curPage -= 1;
			loadSkinTab(curPage);
		}
		
		function addToCart(skin, elt, _ref){
			/*if( isLoggedIn != 1 )
			{
				return;
			}*/
			
			var goptionsStr = goptions.join(',');
			var optionsStr = options.join(',');
			
			if( _ref == undefined )
			{
				_ref = -1;
			}
			
			$.post(url_addtocart, {id: skin, qt: 1, goptions: goptionsStr, options: optionsStr, _ref: _ref}, function(data, status){
				if( data.success == true )
				{
					$(".skinview_buyit_option").fadeTo('normal', 1);
					goptions = [];
					options = [];
					
					$(elt).effect("transfer", { to: "#cartdrop", className: 'ui-effects-transfer' }, 500);
					loadCart();
				}
			}, "json");
		}
		
		function addToWishbox(skin, elt){
			if( isLoggedIn != 1 )
			{
				return;
			}
			
			var goptionsStr = goptions.join(',');
			var optionsStr = options.join(',');
			
			$.post(url_addtowishbox, {id: skin, qt: 1, goptions: goptionsStr, options: optionsStr}, function(data, status){
				if( data.success == true )
				{
					$(".skinview_buyit_option").fadeTo('normal', 1);
					goptions = [];
					options = [];
					$(elt).effect("highlight", {}, 800);
				}
			}, "json");
		}

		function addGOption(id, elt){
			/*if( isLoggedIn != 1 )
			{
				return;
			}*/
			
			if( goptions.indexOf(id) == -1 )
			{
				goptions.push(id);
				$(elt).parent().fadeTo("normal", 0.5);
			}
			else
			{
				delete goptions[goptions.indexOf(id)];
				$(elt).parent().fadeTo("normal", 1);
			}
		}

		function addOption(id, elt){
			/*if( isLoggedIn != 1 )
			{
				return;
			}*/
			
			if( options.indexOf(id) == -1 )
			{
				options.push(id);
				$(elt).parent().fadeTo("normal", 0.5);
			}
			else
			{
				delete options[options.indexOf(id)];
				$(elt).parent().fadeTo("normal", 1);
			}
		}

		function applyTriggerAjax(sel){
			var finalSel;
			
			if( sel == undefined )
			{
				finalSel = 'a.triggerAjax';
			}
			else
			{
				finalSel = sel + ' a.triggerAjax';
			}
			
			$(finalSel).click( function(evt){ 
				triggerAjax($(this));
				evt.stopPropagation();
				evt.preventDefault();
				return false;
			} );
		}		

		function openTab(id, elt){
			$("#menuskintab li").attr("class", "");
			$(elt).parent().attr("class", "active");

			$("#contentskintabback div").hide("slide", "fast");
			$("#" + id).show("slide", "fast");
		}

		function userOnlyTips(sel)
		{
			var finalSel;
			
			if( sel == undefined )
			{
				finalSel = '.userOnly';
			}
			else
			{
				finalSel = sel + ' .userOnly';
			}

			$(finalSel).qtip( {
				content: 'Please login or join to use this feature!',
				position: {
					corner: {
						target: 'topRight',
						tooltip: 'bottomLeft'
					}
				},
				style: {
					border: {
						width: 2
					},
					name: 'light',
					tip: 'bottomLeft'
				},

				show: {
					effect: 'fade',
					when: {
						event: 'mouseover'
					}
				},
				
				hide: {
					effect: 'fade'
				}
			} );
		}

		function largerThumbnailPreview()
		{
			$("#skinsPlaceholder li img").css({width: '130px', height: '113px'});
			
			$("#skinsPlaceholder li").hover(function() {
				$(this).css({'z-index' : '10'});
				$(this).find('img').addClass("hover").stop()
					.animate({
						marginTop: '-120px', 
						marginLeft: '-120px', 
						top: '0%', 
						left: '0%', 
						width: '379px', 
						height: '298px',
						padding: '20px' 
					}, 200);
				
			} , function() {
				$(this).css({'z-index' : '0'});
				$(this).find('img').removeClass("hover").stop()
					.animate({
						marginTop: '0', 
						marginLeft: '0',
						top: '0', 
						left: '0', 
						width: '130px', 
						height: '113px', 
						padding: '0'
					}, 400);
			});

			$("ul.thumb li a").click(function() {		
				var mainImage = $(this).attr("href"); //Find Image Name
				$("#main_view img").attr({ src: mainImage });
				//return false;		
			});
		}

		function menu(){
			$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
			
			$("ul.topnav li span").click(function() { //When trigger is clicked...
				
				//Following events are applied to the subnav itself (moving subnav up and down)
				$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

				$(this).parent().hover(function() {
				}, function(){	
					$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				});

				//Following events are applied to the trigger (Hover events for the trigger)
				}).hover(function() { 
					$(this).addClass("subhover"); //On hover over, add class "subhover"
				}, function(){	//On Hover Out
					$(this).removeClass("subhover"); //On hover out, remove class "subhover"
			});

			$('ul.drawers').accordion({
	            header: 'H2.drawer-handle',
	            selectedClass: 'open',
	            event: 'mouseover'
	        });
		}
		
		function saveCategoryOrder(elt)
		{
			var data = $('.sortable').sortable('serialize');
			
			$.post(url_savecategory, data, function(response, status){
				if( response.success == false )
				{
					alert('Error on category order saving');
				}
				else
				{
					alert('Saved!');
				}
			});
		}
		
		function reviewForm(skin_id, review_id)
		{
			var mode = 'create';
			
			if( review_id != undefined )
			{
				mode = 'edit';
			}
			
			$.fn.colorbox({
				href: url_reviewform + skin_id + "&mode=" + mode + "&review=" + review_id,
				width: false,
				height: false,
				open: true
			});
			
			$().bind('cbox_complete', function(){
				$("#review").submit( function(){
					saveReview($("#review"), skin_id, mode, review_id);
					
					return false;
				} );
				
				$().unbind('cbox_complete');
			});
		}
		
		function saveReview(elt, skin_id, mode, review_id)
		{
			var query = elt.serialize();
			
			$.post( url_savereview + skin_id + "&mode=" + mode + "&review=" + review_id, query, function( data, status ){
				if( data.success == true )
				{
					$.fn.colorbox.close();
					$().bind("cbox_closed", function(){
						loadReview(skin_id, 1);
						$().unbind("cbox_closed");
					} );
				}
				else
				{
				}
			}, "json" );
		}
		
		var revskin = 0;
		
		function loadReview(skin_id, offset)
		{
			if( offset == undefined )
			{
				offset = 1;
			}
			
			revskin = skin_id;
			
			$("#review").fadeOut();
			
			$("#review").load(url_loadreview + skin_id + '&offset=' + offset, null, function(){
				$("#review").fadeIn();
			});
		}
		
		function deleteReview(review_id)
		{
			$.get( url_deletereview + review_id, null, function( data, status ){
				if( data.success == true )
				{
					alert('Deleted successfully!');
					loadReview(revskin, 1);
				}
				else
				{
					alert('Error while deleting');
				}
			}, 'json');
		}
		
		function sendToFriend(elt, skin_id)
		{
			var query = $("#sendtofriend form").serialize();
			
			$.post( url_sendtofriend + skin_id, query, function(data, status){
				if( data.success == true )
				{
					$.fn.colorbox.close();
					$().bind('cbox_closed', function(){
						$().unbind('cbox_closed');
						$("#sendtofriendmsg").html("Email(s) sent!");
						$.fn.colorbox({href:"#sendtofriendmsg", inline: true, open: true});
					});
				}
				else
				{
					$.fn.colorbox.close()
					$().bind('cbox_closed', function(){
						$().unbind('cbox_closed');
						$("#sendtofriendmsg").html( "The following error(s) occured:<br />" + Array.join(data['messages']) + "<br />" + $("#sendtofriend").html() );
						$.fn.colorbox({href: "#sendtofriendmsg", inline: true, open: true});
					});
				}
			}, 'json');
		}