//*************************This is for the slider on the main page
$(document).ready(function(){
    // run the code in the markup!
	$('#slider_area').cycle({ 
		fx:     'fade', 
		//easing: 'bounceout', 
		timeout:11000,        
		prev:   '.prev',
		next:   '.next'
	});

	$('#slider2').cycle({ 
		fx:     'scrollUp', 
		//easing: 'backinout', 
		timeout:11000,        
		prev:   '.test_arrows_left',
		next:   '.test_arrows_right'
	});
	
	$('.slide_2').corner("20px");
	$('.slide_3').corner("20px");
});


//*************************This is for the gallery photo section
$(document).ready(function(){
	$("#albums a").bind("click", function(){
		$("#a_title").text($(this).attr('title'));
		$("#pic_holder").html('<div class="loading"><img src="./images/loading.gif" alt="Loading..."></div>').load("./js/_ajax.php",{"aID":$(this).attr("ref")},function(){
			$("#pic_holder").find("a").fancybox();
		});
	});
});






//*************************This is the contact form script
$(document).ready(function(){
	$("form#contact_form").submit(function(){
		var str = $("form").serialize();
		$.ajax({
		type: "POST",
		url: "contactform/contact.php",
		data: str,
		success: function(msg){
			$("#note").ajaxComplete(function(event, request, settings){
				if(msg == 'OK'){ 	// Message Sent? Show the 'Thank You' message and hide the form
					result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
					$("#fields").hide();
				}else{
					result = msg;
				}
				$(this).html(result);
			});
		}});
		return false;
	});
});
//end contact form script


/******Checks if the number is numeric***********************/
function IsNumeric(stext) {
	var valid_chars = "0123456789.$";
	var IsNumber=true;
	var single_char;
 
	for (var i = 0; i < stext.length && IsNumber == true; i++) { 
		single_char = stext.charAt(i); 
		if (valid_chars.indexOf(single_char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}



//******This is for the Shopping cart**************************/
//simpleCart.email = "ace.ho_1268179021_biz@gmail.com";
simpleCart.email = "lena@musesigns.com";
simpleCart.checkoutTo = PayPal;
simpleCart.currency = CAD;
var sPath;
var sPage;
var num_products = 0;

$(document).ready(function() {
	sPath = window.location.pathname;
	sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

	$('a#product_image').fancybox();
	$('a#standard_image').fancybox();
	
	$.reject();
	
	set_cart_names();
	is_cart_empty();
	add_cart_spacing();
	
	if (sPage.toLowerCase() != "customquotes.php" && sPage.toLowerCase() != "address.php") {
		set_init_prices();
	}

	$("#product_addto_cart").css("opacity", "0.0");
	$('.item_add').click(function(){
		$(this).siblings('#product_addto_cart').animate( { opacity:"1.0"}, 1500 )
			.animate( { fontSize:"10px" } , 1000 )
			.animate( { opacity:"0.0" }, 1000);
	
		set_cart_names();
		add_cart_spacing();
		is_cart_empty();
	});
	
	$('.simpleCart_empty').click(function(){
		is_cart_empty();
	});

	$('.simpleCart_shelfItem > .item_size').change(function(e) {
		e.stopPropagation();
		if (sPage.toLowerCase() != "customquotes.php" && sPage.toLowerCase() != "address.php"){
			if ($(this).val() == "small")
				$(this).siblings('.item_price').text('$' + $(this).siblings('#small_price').val() + '.00');
			if ($(this).val() == "medium")
				$(this).siblings('.item_price').text('$' + $(this).siblings('#medium_price').val() + '.00');
			if ($(this).val() == "large")
				$(this).siblings('.item_price').text('$' + $(this).siblings('#large_price').val() + '.00');
			if ($(this).val() == "extralarge")
				$(this).siblings('.item_price').text('$' + $(this).siblings('#extralarge_price').val() + '.00');
		}
	});
	

	$('#custom_color_input').colorPicker({			
		defaultColor: 8, 								// index of the default color (optional)
		click: function(color){$('#custom_color_output').html(color.substring(1));}, 
	});
	$('#address_color_input').colorPicker({			
		defaultColor: 0, 								// index of the default color (optional)
		color: ['#000000', '#FFFFFF', '#B3A195'], 		// list of colors (optional)
		click: function(color){$('#address_color_output').html(color.substring(1));}, 
	});	

	if (sPage.toLowerCase() == 'shoppingcart.php') 
		load_cart_pics();
});

/******Sets the initial prices for the items*****************************/
function set_init_prices(){
	$('.simpleCart_shelfItem').each(function() {
		if ($(this).children('.item_size').val() == "small")
			$(this).children('.item_price').text('$' + $(this).children('#small_price').val() + '.00');
		if ($(this).children('.item_size').val() == "medium")
			$(this).children('.item_price').text('$' + $(this).children('#medium_price').val() + '.00');
		if ($(this).children('.item_size').val() == "large")
			$(this).children('.item_price').text('$' + $(this).children('#large_price').val() + '.00');
		if ($(this).children('.item_size').val() == "extralarge")
			$(this).children('.item_price').text('$' + $(this).children('#extralarge_price').val() + '.00');
	});
}


/******Adds spacing between the products in the shopping cart**************************/
function add_cart_spacing() {
	if (sPage.toLowerCase() != 'shoppingcart.php') {
		$('.itemContainer > .itemColor').after('<div style="clear:both;"></div>');
		$('.itemContainer > .itemQuantity').after('<div style="clear:both;"></div>');
		$('.itemContainer > .itemQuantity').after('<br />');
	} else {
		$('.cartHeaders').after('<div style="clear:both;"></div>');
		$('.cartHeaders').after('<br />');
		$('.itemRemove').after('<div style="clear:both;"></div>');
	}
	
}
/******Checks if the cart is empty and then removes or adds the empty and checkout buttons**************************/
function is_cart_empty(){
	var cart_empty = 0;
	$('.simpleCart_items').children().each(function() {
		if ($(this).hasClass('itemContainer'))
			cart_empty = 1;
	});
	if (cart_empty == 1) {
		$('.simpleCart_empty').removeClass('hidden');
		$('.simpleCart_checkout').removeClass('hidden');
	} else {
		$('.simpleCart_empty').addClass('hidden');
		$('.simpleCart_checkout').addClass('hidden');
	}
}

/******Sets the names of each item in the bubble shopping cart**************************/
function set_cart_names(){
	var strTitle;
	$('.itemContainer').each(function() {
	
		strTitle = 'Item: ' + $(this).children('.itemName').text();
		$(this).children('.itemName').text(strTitle);
		
		strTitle = 'Size: ' + $(this).children('.itemSize').text();
		$(this).children('.itemSize').text(strTitle);
		
		strTitle = 'Color: ' + get_color_name($(this).children('.itemColor').text());
		$(this).children('.itemColor').text(strTitle);
		
		strTitle = 'Price: ' + $(this).children('.itemPrice').text();
		$(this).children('.itemPrice').text(strTitle);
		
		strTitle = 'Qty: ' + $(this).children('.itemQuantity').text();
		$(this).children('.itemQuantity').text(strTitle);
		
		strTitle = 'Sub-Total: ' + $(this).children('.itemTotal').text();
		$(this).children('.itemTotal').text(strTitle);
	});
}

/******Gets the name of the color**************************/
function get_color_name(color_code){
	if (color_code == "000000")
		color_code = "black";
	else if (color_code == "FFFFFF")
		color_code = "white";
	else if (color_code == "959595")
		color_code = "grey";
	else if (color_code == "FFE600")
		color_code = "yellow";
	else if (color_code == "F15A22")
		color_code = "orange";
	else if (color_code == "B3D234")
		color_code = "green";
	else if (color_code == "00ADEF")
		color_code = "blue";
	else if (color_code == "EF4123")
		color_code = "red";
	else if (color_code == "7A4418")
		color_code = "brown";
	else if (color_code == "F391BC")
		color_code = "pink";
	else if (color_code == "9474B4")
		color_code = "purple";
	else if (color_code == "EC008C")
		color_code = "dark pink";
	else if (color_code == "0DB14B")
		color_code = "dark green";
	return color_code;
}

/******Loads the small pics for each cart item*/
function load_cart_pics() {
	if (sPage.toLowerCase() == 'shoppingcart.php') {
		$('.itemContainer').each(function() {
			var picNameLong = $(this).children('.itemName').text();
			var picName = picNameLong.substring(6).toLowerCase().replace(/ /gi, "_").replace("!","").replace(",","").replace("&","and");
			var picSrc = 'images/products/' + picName + '_small.jpg';
			$(this).children('.itemName').before('<div id="itemPic" style="float: left;"><img src=' + picSrc + ' alt=' + $(this).children(".itemName").text() + ' /></div>');
		});

		$('#itemPic > img').css({	"border":"3px solid #FFFFFF",
									"width":"104px",
									"height":"75px",
									"margin-right":"7px"});
		$('.itemdecrement').after("<br />");
	}
}

/******Loads the desired font**************************/

/*var oldfilename = "js/fontfiles/twilight_400.font.js";

function load_font(font_name) {
	if (font_name == "affair") {
		replacejscssfile(oldfilename, "js/fontfiles/affair_400.font.js", "js");
		oldfilename = "js/fontfiles/affair_400.font.js";
	}
	else if (font_name == "boyzrgross") {
		replacejscssfile(oldfilename, "js/fontfiles/boyzrgross_400.font.js", "js");
		oldfilename = "js/fontfiles/boyzrgross_400.font.js";
	}
	else if (font_name == "buffet_script") {
		replacejscssfile(oldfilename, "js/fontfiles/buffet_script_400.font.js", "js");
		oldfilename = "js/fontfiles/buffet_script_400.font.js";
	}
	else if (font_name == "bulmer") {
		replacejscssfile(oldfilename, "js/fontfiles/bulmer_400.font.js", "js");
		oldfilename = "js/fontfiles/bulmer_400.font.js";
	}
	else if (font_name == "buttons") {
		replacejscssfile(oldfilename, "js/fontfiles/buttons_400.font.js", "js");
		oldfilename = "js/fontfiles/buttons_400.font.js";
	}
	else if (font_name == "candy_script") {
		replacejscssfile(oldfilename, "js/fontfiles/candy_script_400.font.js", "js");
		oldfilename = "js/fontfiles/candy_script_400.font.js";
	}
	else if (font_name == "champagne_limousines") {
		replacejscssfile(oldfilename, "js/fontfiles/champagne_limousines_300.font.js", "js");
		oldfilename = "js/fontfiles/champagne_limousines_300.font.js";
	}
	else if (font_name == "champagne_limousines_bold") {
		replacejscssfile(oldfilename, "js/fontfiles/champagne_limousines_bold_700.font.js", "js");
		oldfilename = "js/fontfiles/champagne_limousines_bold_700.font.js";
	}
	else if (font_name == "champignon") {
		replacejscssfile(oldfilename, "js/fontfiles/champignon_500.font.js", "js");
		oldfilename = "js/fontfiles/champignon_500.font.js";
	}
	else if (font_name == "delicious_bold") {
		replacejscssfile(oldfilename, "js/fontfiles/delicious_bold_700.font.js", "js");
		oldfilename = "js/fontfiles/delicious_bold_700.font.js";
	}
	else if (font_name == "delicious_bolditalic") {
		replacejscssfile(oldfilename, "js/fontfiles/delicious_bolditalic_italic_700.font.js", "js");
		oldfilename = "js/fontfiles/delicious_bolditalic_italic_700.font.js";
	}
	else if (font_name == "delicious_heavy") {
		replacejscssfile(oldfilename, "js/fontfiles/delicious_heavy_500.font.js", "js");
		oldfilename = "js/fontfiles/delicious_heavy_500.font.js";
	}
	else if (font_name == "delicious_italic") {
		replacejscssfile(oldfilename, "js/fontfiles/delicious_italic_italic_500.font.js", "js");
		oldfilename = "js/fontfiles/delicious_italic_italic_500.font.js";
	}
	else if (font_name == "delicious_roman") {
		replacejscssfile(oldfilename, "js/fontfiles/delicious_roman_500.font.js", "js");
		oldfilename = "js/fontfiles/delicious_roman_500.font.js";
	}
	else if (font_name == "delicious_smallcaps") {
		replacejscssfile(oldfilename, "js/fontfiles/delicious_smallcaps_500.font.js", "js");
		oldfilename = "js/fontfiles/delicious_smallcaps_500.font.js";
	}
	else if (font_name == "diavlo_black_ii") {
		replacejscssfile(oldfilename, "js/fontfiles/diavlo_black_ii_900.font.js", "js");
		oldfilename = "js/fontfiles/diavlo_black_ii_900.font.js";
	}
	else if (font_name == "diavlo_bold_ii") {
		replacejscssfile(oldfilename, "js/fontfiles/diavlo_bold_ii_700.font.js", "js");
		oldfilename = "js/fontfiles/diavlo_bold_ii_700.font.js";
	}
	else if (font_name == "diavlo_medium_ii") {
		replacejscssfile(oldfilename, "js/fontfiles/diavlo_medium_ii_500.font.js", "js");
		oldfilename = "js/fontfiles/diavlo_medium_ii_500.font.js";
	}
	else if (font_name == "dingle_sw") {
		replacejscssfile(oldfilename, "js/fontfiles/dingle_sw_400.font.js", "js");
		oldfilename = "js/fontfiles/dingle_sw_400.font.js";
	}
	else if (font_name == "eight_one") {
		replacejscssfile(oldfilename, "js/fontfiles/eight_one_400.font.js", "js");
		oldfilename = "js/fontfiles/eight_one_400.font.js";
	}
	else if (font_name == "jane_aust") {
		replacejscssfile(oldfilename, "js/fontfiles/jane_aust_400.font.js", "js");
		oldfilename = "js/fontfiles/jane_aust_400.font.js";
	}
	else if (font_name == "katy_berry") {
		replacejscssfile(oldfilename, "js/fontfiles/katy_berry_400.font.js", "js");
		oldfilename = "js/fontfiles/katy_berry_400.font.js";
	}
	else if (font_name == "little_lord") {
		replacejscssfile(oldfilename, "js/fontfiles/little_lord_400.font.js", "js");
		oldfilename = "js/fontfiles/little_lord_400.font.js";
	}
	else if (font_name == "ma_sexy") {
		replacejscssfile(oldfilename, "js/fontfiles/ma_sexy_400.font.js", "js");
		oldfilename = "js/fontfiles/ma_sexy_400.font.js";
	}
	else if (font_name == "melanie_bt_roman") {
		replacejscssfile(oldfilename, "js/fontfiles/melanie_bt_roman_400.font.js", "js");
		oldfilename = "js/fontfiles/melanie_bt_roman_400.font.js";
	}
	else if (font_name == "old_script") {
		replacejscssfile(oldfilename, "js/fontfiles/old_script_400.font.js", "js");
		oldfilename = "js/fontfiles/old_script_400.font.js";
	}
	else if (font_name == "pavane") {
		replacejscssfile(oldfilename, "js/fontfiles/pavane_400.font.js", "js");
		oldfilename = "js/fontfiles/pavane_400.font.js";
	}
	else if (font_name == "twilight") {
		replacejscssfile(oldfilename, "js/fontfiles/twilight_400.font.js", "js");
		oldfilename = "js/fontfiles/twilight_400.font.js";
	}
	else if (font_name == "vag_rounded_bt") {
		replacejscssfile(oldfilename, "js/fontfiles/vag_rounded_bt_400.font.js", "js");
		oldfilename = "js/fontfiles/vag_rounded_bt_400.font.js";
	}
	else if (font_name == "varsity_regular") {
		replacejscssfile(oldfilename, "js/fontfiles/varsity_regular_400.font.js", "js");
		oldfilename = "js/fontfiles/varsity_regular_400.font.js";
	}
	else if (font_name == "waterfalls") {
		replacejscssfile(oldfilename, "js/fontfiles/waterfalls_400.font.js", "js");
		oldfilename = "js/fontfiles/waterfalls_400.font.js";
	}
}
*/
function load_fonts(custom) {
	if (custom == 1) {
		createjscssfile("js/fontfiles/affair_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/boyzrgross_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/buttons_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/dingle_sw_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/eight_one_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/katy_berry_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/little_lord_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/ma_sexy_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/melanie_bt_roman_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/vag_rounded_bt_400.font.js", "js", 1);
		createjscssfile("js/fontfiles/varsity_regular_400.font.js", "js", 1);
	}
	createjscssfile("js/fontfiles/buffet_script_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/bulmer_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/candy_script_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/champagne_limousines_300.font.js", "js", 1);
	createjscssfile("js/fontfiles/champagne_limousines_bold_700.font.js", "js", 1);
	createjscssfile("js/fontfiles/champignon_500.font.js", "js", 1);
	createjscssfile("js/fontfiles/delicious_bold_700.font.js", "js", 1);
	createjscssfile("js/fontfiles/delicious_bolditalic_italic_700.font.js", "js", 1);
	createjscssfile("js/fontfiles/delicious_heavy_500.font.js", "js", 1);
	createjscssfile("js/fontfiles/delicious_italic_italic_500.font.js", "js", 1);
	createjscssfile("js/fontfiles/delicious_roman_500.font.js", "js", 1);
	createjscssfile("js/fontfiles/delicious_smallcaps_500.font.js", "js", 1);
	createjscssfile("js/fontfiles/diavlo_black_ii_900.font.js", "js", 1);
	createjscssfile("js/fontfiles/diavlo_bold_ii_700.font.js", "js", 1);
	createjscssfile("js/fontfiles/diavlo_medium_ii_500.font.js", "js", 1);
	createjscssfile("js/fontfiles/jane_aust_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/old_script_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/pavane_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/twilight_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/waterfalls_400.font.js", "js", 1);
	
	createjscssfile("js/fontfiles/aurora_script_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/ceremonious_three_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/copyist_100.font.js", "js", 1);
	createjscssfile("js/fontfiles/esenin_script_one_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/feel_script_400.font.js", "js", 1);
	createjscssfile("js/fontfiles/sue_ellen_fransisco_400.font.js", "js", 1);
}



/******Creates the desired script/css element********************/
function createjscssfile(filename, filetype, init){
	if (filetype=="js"){ //if filename is a external JavaScript file
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", filename)
	}
	else if (filetype=="css"){ //if filename is an external CSS file
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", filename)
	}
	if (init = 0)
		return fileref
	else
		document.getElementsByTagName("head")[0].appendChild(fileref)
}

/******Replaces the existing script element with the new one*******************/
function replacejscssfile(oldfilename, newfilename, filetype){
	var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
	var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
	var allsuspects=document.getElementsByTagName(targetelement)
	for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
		if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
			var newelement=createjscssfile(newfilename, filetype, 0)
			allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
		}
	}
}

