

$(window).load(function() {
						
	setupLightBoxes() ;
	createToolTips() ;
	createDatePickers();
	//$('.selectMenu').selectmenu({width:200}); 
	
	disabledOpacity() ;
	setUpSubItemToggling();
	setUpHighlites();
	setupFieldsets();
	
	setupUploadForms();
	
});

function dropOut( id ){
		$('#' + id).hide( 'drop', { direction: "down" }, 200, function() { $(this).remove( ); } );			  
}
function jQDropOut( selector ){
		$(selector).hide( 'drop', { direction: "down" }, 200, function() { $(this).remove( ); } );			  
}

function setupUploadForms(){
	
	$('form.upload_form').submit(function(){	
										  
		showUserLoader('modal_window','Uploading...please wait');			  
										  
		$( "#modal_window" ).dialog({
			autoOpen: true,
			width: 200,
			height: 200,
			zIndex: 9001,
			title: false,
			modal: true,
			close: function() {
				
			}
		});	
										  
	});
	
	
	
}

function showUserLoader(divid, message){

	var loadingHTML = '<div class="loading_panel"><img src="' + url_to_template  + '/images/loading.gif" />' ;
	loadingHTML += '<p>' + message + '</p>' ;
	loadingHTML += '</div>' ;
	$('#'+divid).html(loadingHTML) ;	
}

function showHorizontalLoader(divId){
		
		var loadingHTML = '<img src="' + url_to_template  + '/images/horizontal_loader.gif" />' ;
		$('#'+divId).html(loadingHTML) ;	
	
}
	

function setupFieldsets(){
	
  $('fieldset.toggle:not(.startopen) > legend').siblings().hide();
	
  $('fieldset.toggle > legend').click(function(){
   	$(this).siblings().slideToggle("slow");
	$(this).toggleClass('open') ;
  });

}

function disabledOpacity(){
	
	$(".disabled_row input[type=text], .disabled_row .matrix_firstcol, input.disabled, td.disabled label").css({ opacity: 0.2 });
	
	$("div.block.inactive").css({ opacity: 0.4 });
	
}

function createToolTips(){
	$(".helpicon").tipTip(
						  
						  {delay:100}
						  );
}

function createDatePickers(){
	$('.date_picker').datepicker( { dateFormat: 'd M yy'} );	
}

function setupLightBoxes(){

    $("a[rel^='prettyPhoto']").prettyPhoto({
										   default_width: 1000,
											default_height: 600
										   			
										   });
	//$('a.lightbox_image').prettyPhoto(); 

	//$('a.lightbox_image').lightBox({fixedNavigation:true});
}

function setSource( element, src ){
	$(element).attr('src',src) ;	
}

function toggleDelivery(){
		
		if(document.checkoutform.delivercheck.checked == true){
			document.checkoutform.deliveryfirstname.value = document.checkoutform.firstname.value;
			document.checkoutform.deliverysecondname.value = document.checkoutform.secondname.value;
			document.checkoutform.deliveryaddress1.value = document.checkoutform.address1.value;
			document.checkoutform.deliveryaddress2.value = document.checkoutform.address2.value;
			document.checkoutform.deliverycity.value = document.checkoutform.city.value;
			document.checkoutform.deliverycounty.value = document.checkoutform.county.value;
			document.checkoutform.deliverypostcode.value = document.checkoutform.postcode.value;	
		}else{
			document.checkoutform.deliveryfirstname.value = '';
			document.checkoutform.deliverysecondname.value = '';
			document.checkoutform.deliveryaddress1.value = '';
			document.checkoutform.deliveryaddress2.value = '';
			document.checkoutform.deliverycounty.value = '';
			document.checkoutform.deliverycity.value = '';
			document.checkoutform.deliverypostcode.value = '';	
		}
	
	}


function load(file,target) {
    if (target != '')
        target.window.location.href = file;
    else
        window.location.href = file;
}

function setUpSubItemToggling(){
	
		$('input.toggleSubItems').click(function(){
												 
			if($(this).is(":checked")){	
				$('input',$(this).closest('div.category_option_set')).attr('checked',true) ;
				toggleHighlites() ;
			}else{
				$('input',$(this).closest('div.category_option_set')).attr('checked',false) ;
				toggleHighlites() ;
			}				
												 
		}) ;
	
}



function setUpHighlites(){
	
	$('div.item_option input').click(function(){
											 
											 toggleHighlites() ;
											 
											 });
}

function toggleHighlites(){
		
	$('div.item_option input').each(function(){
											 										 
			if($(this).is(":checked")){	
				$(this).closest('div.item_option').addClass('option_selected') ;
			}else{
				$(this).closest('div.item_option').removeClass('option_selected') ;
			}									 
											 
	 });
		
}

function deleteUserFile(userFileId){
	
	if (confirm("Are you sure you want to delete this file?")) {
			
			var postBody = "action=deleteuserfile&fileid=" + userFileId;
			
			$.ajax({
				  url: fullURL + '/inc/ajax_product.php',
				  type: 'POST',
				  data: postBody,
				  success: function(responseText){  
					  jQDropOut('div.image_userfile_' + userFileId + ', div.userfile_' + userFileId);
					 // reloadImageCategories() ;
				  }
				});
			
		}
	
}

 function toggleExpand(icon){
	 	
		icon.toggleClass('expanded') ;
		var li = icon.closest('li');
	  
		$('>ul',li).slideToggle('slow', function() {
			
		});
		
 }

function togglePanel(icon, identifer){
	
	icon.toggleClass('down') ;	
	
	$(identifer).slideToggle('slow', 'easeOutBounce', function() {
			
		});
}


function loadItemContent(itemType, itemId, contentType, holderId){
	
		showHorizontalLoader(holderId) ;
		
		var url = fullURL + "/inc/ajax_product.php" ;
		var postData ;
		postData = "action=loaditemcontent" ;
		postData += "&itemtype=" + itemType ;
		postData += "&itemid=" + itemId ;
		postData += "&contenttype=" + contentType ;
	
		$.ajax({
		  url: url,
		  type: 'POST',
		  data: postData,
		  success: function(responseText){
			  
				$('#' + holderId).html(responseText) ;
			
		  }
		});
			
		
	}
		
