$( function() {
	Asspaginator( 1 );
	
	$( '#movieIcon').click( function(){
		$(".ytvideos").slideDown("normal");
	} );
	
	
	/*
	IRONING BOARD COVERS
	*/
	$( '#MoreInfo' ).submit( function( event ) {
		if ( in_array( $( "#viewingUPID" ).val(), [1912, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1865, 1770, 1842, 1862, 1863, 1864, 1676, 1675, 1674, 1673, 1596, 1599, 1598, 1539, 1538, 1537, 1536, 1525, 1535, 1533, 1532, 1528, 1527, 1600, 1526, 1529, 1530, 1531, 1534] ) ) {
			//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': 10,
			'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");
}
