$(document).ready(function() {
//	$( '#productDescriptionLink' ).click( function() {
//		swapTab( '#productDescription' );
//	} ).click();
//	$( '#reviewsLink' ).click( function() {
//		swapTab( '#reviews' );
//	} );
	
	Asspaginator( 1 );
	
	$( '#movieIcon').click( function(){
		$(".ytvideos").slideDown("normal");
	} );
	
	
	/*
	IRONING BOARD COVERS
	*/
	$( '#MoreInfo' ).submit( function( event ) {
		if ( in_array( $( "input:radio:checked[name='PID']" ).val(), [2296, 2297, 2298, 2299, 2300, 2301, 2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312, 2313, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324, 2325, 2326, 2327, 2328, 2329, 2330, 2331, 2332, 2333, 2334, 2335, 2336, 2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344, 2345, 2346, 2347, 2348, 2349, 2350, 2351, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, 2587, 2588, 2589, 2590, 2591, 2592, 2593, 2819, 2820, 2821, 2822, 2823, 2824, 2825, 2826, 2827, 2828, 2829, 2830, 2831, 2832, 2833, 2834] ) ) {
			//Cancel the link behavior
			event.preventDefault();
			//Get the A tag
			var id = '#dialog';
		
			//Get the screen height and width
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
		
			//Set height and width to mask to fill up the whole screen
			$('#mask').css({'width':maskWidth,'height':maskHeight});
			
			//transition effect		
			$('#mask').fadeIn(1000);	
			$('#mask').fadeTo("slow",0.8);	
		
			//Get the window height and width
			var winH = $(window).height();
			var winW = $(window).width();
				  
			//Set the popup window to center
			$('#dialog').css('top',  winH/2-$(id).height()/2);
			$('#dialog').css('left', winW/2-$(id).width()/2);
		
			//transition effect
			$('#dialog').fadeIn(2000); 
		}
	} );
	
	//if close button is clicked
	$('.window .close').click(function () {
		//Cancel the link behavior
		$('#mask, .window').hide();
		alert( 'Please try again when you are sure your board is the correct size & shape.' );
	});	
	
	$('.window .ok').click( function() {
		var URL = '/action.php?action=add&Quantity=' + $( "#Quantity" ).val() + '&PID=' + $( "input:radio:checked[name='PID']" ).val()
		if ( $( "input:checkbox:checked[name='AssProducts[]']" ) ) URL += '&AssProducts[]=' + $( "input:checkbox:checked[name='AssProducts[]']" ).val();
		document.location = URL;
	} );
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
	
	
	/*
	ALT TAGS
	*/
	$( '#editAltLinks' ).click( function( event ) {
		//Set height and width to mask to fill up the whole screen
		$('#altTagmask').css( {
			'width': $(window).width(),
			'height': $(document).height()
		} ).fadeIn( 1000 ).fadeTo( "slow", 0.8 );	
	
		//Set the popup window to center
		$('#altTagdialog').css( {
			'top': ( $( window ).height() / 2 ) - ( $( '#altTagdialog' ).height() / 2 ),
			'left': ( $( window ).width() / 2 ) - ( $( '#altTagdialog' ).width() / 2 )
		} ).fadeIn( 2000, function() {
			$( '.editableALT' ).blur( function() {
				var thisName = $( this ).attr( 'name' );
				$.ajax({
					url: '/backend/ajax/inlineUpdate.php?tablename=zadmin_zcart_products_translations&fieldname=' + thisName + '&value=' + escape( $( this ).val() ) + '&id=' + $( this ).attr( 'id' ),
					cache: false,
					success: function( data ) {
						if ( data == 'OK' ) {
							$( '#result_' + thisName ).html( 'Saved' );
						} else {
							$( '#result_' + thisName ).html( 'Error saving' );
						}
					}
				});
			} );

		} ); 
	} );
	
	//if close button is clicked
	$('.altTagwindow .altTagclose, #altTagmask').click(function () {
		//Cancel the link behavior
		$('#altTagmask, .altTagwindow').hide();
		location.reload();
	});	
});

function forcePurchase( number ) {
	$( "input:radio[name='PID']" ).each( function() {
		if ( $( this ).attr( 'id' ) == number ) {
			$( this ).attr( 'checked', true );
		} else {
			$( this ).removeAttr( 'checked' );
		}
	} );
	
	$( '#MoreInfo' ).submit();
}

function in_array (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) return true;
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) return true;
        }
    }

    return false;
}

function Asspaginator( openerID ) {
	$(".paginateAssSurround").slideUp("normal");
	$("#paginateAss"+openerID).slideDown("normal");
}

function swapTab( tabToOpen ) {
	var tabs = [ '#reviews', '#productDescription' ];
	
	for ( var i = 0; i < tabs.length; i++ ) {
//		$( tabs[i] ).hide();
	}
	
//	$( tabToOpen ).show();
}
