$(document).ready(function () {


// ======================= FOR PRODUCT PAGE COLOUR HELP POP UP BUTTON  - No Plugin - Jquery function =========================

$("div.product_option_4").append("<div class='colour_help_position'><a class='help_button colour_help'>Help</a><div class='help_pop_up colour_pop_up' style='display: none;'><p class='form_text'>Please see examples of colours above.</p></div></div>"); 


// ======================= FOR BEDS PRODUCT PAGE DRAWER CONFIG IMAGES  - No Plugin - Jquery function =========================

$("div.product_option_2").append("<div style='' id='divProductOptionImage'></div>"); 


// ======================= FOR GALLERY ON PRODUCT PAGE - No Plugin - Jquery function =========================

	$("#thumbs a").click(function (e) {
		e.preventDefault();
		curIndex = $(this).attr("rel");
		var mediumPath = $(this).attr("href");
		$("#largeImg a img").attr({ src: mediumPath });
	});


	$(".thumbsHome a").click(function (e) {

		try {
			e.preventDefault();
			//alert($(this).attr("ID"));
			var largePath = $(this).attr("href");
			//alert(largePath);
			var largeTitle = $(this).attr("title");

			var ControlID = $(this).attr("ID");

			var productImageID = ControlID;
			productImageID = productImageID.replace("_thumb1HyperLink", "_productImageHyperLink");
			productImageID = productImageID.replace("_thumb2HyperLink", "_productImageHyperLink");
			productImageID = productImageID.replace("_thumb3HyperLink", "_productImageHyperLink");
			productImageID = productImageID.replace("_thumb4HyperLink", "_productImageHyperLink");
			productImageID = productImageID.replace("_thumb5HyperLink", "_productImageHyperLink");

			var ObjproductImage = document.getElementById(productImageID);
			//alert(ObjproductImage);
			//alert(document.getElementById(productImageID).title);
			var productImageTitle = ObjproductImage.title;
			productImageTitle = productImageTitle.replace('\'', '');
			//alert(productImageTitle);

			var productImageHyperLink = ObjproductImage.href;

			var LargeImgDivID = '';
			LargeImgDivID = ControlID;
			LargeImgDivID = LargeImgDivID.replace("_thumb1HyperLink", "_largeImg");
			LargeImgDivID = LargeImgDivID.replace("_thumb2HyperLink", "_largeImg");
			LargeImgDivID = LargeImgDivID.replace("_thumb3HyperLink", "_largeImg");
			LargeImgDivID = LargeImgDivID.replace("_thumb4HyperLink", "_largeImg");
			LargeImgDivID = LargeImgDivID.replace("_thumb5HyperLink", "_largeImg");
			//alert(LargeImgDivID);
			//alert(document.getElementById(LargeImgDivID).innerHTML);
			//document.getElementById(LargeImgDivID).innerHTML = "<img src='" + largePath + "' />";
			document.getElementById(LargeImgDivID).innerHTML = "<a id='" + productImageID + "' title='" + productImageTitle + "' class='productimage' href='" + productImageHyperLink + "'> <img title='" + productImageTitle + "' src='" + largePath + "' style='border-width:0px;' /> </a>";
		}
		catch (ex) {
			var error = ex;
			//alert(error);
		}
	});
	
	$("#thumbsHome a").preload();


// ======================= ADD PRINT BUTTON TO BOTTOM UL- No Plugin - Jquery function =========================

	$('a#print_page_link').click(function () {
		window.print();
		return false;
	});


// ======================= HOME PAGE OFFER ROTATOR - jQuery Cycle Plugin - jquery.cycle.all.min.js =========================

	$('div.banner_rotator')
	.cycle({ 
		fx:      'fade', 
		speed:    4000, 
		pager:  '.banner_nav' 
	});


// ======================= FOR CHECKOUT  - No Plugin - Jquery function =========================

	$('a.showsecuritycode').click(function () {
		$('#securitycode').toggle(300);
		return false;
	});
	
	
// ======================= FOR PRODUCT PAGE IMAGE GALLERY - Fancy Box - jquery.fancybox-1.3.1.js =========================
	
	$(".pop_up_window").fancybox({
		'speedIn': 600,
		'speedOut': 200,
		'autoScale': true,
		'autoDimensions': true,
		'padding': 10,
		'margin': 0,
		'scrolling': 'no',
		'overlayColor': '#000',
		'overlayOpacity': 0.6,
		'showNavArrows': false,
		'titleShow': false
	});
	
	
// ======================= FOR PRODUCT PAGE HELP ICONS - No Plugin - Jquery function =========================
	
	$("#ClosePopup").live("click", function (e) {
		e.preventDefault();
		$.fancybox.close();
	});


//========================= ADD STRONG TAG TO FIRST WORD TO MAKE FIRST HEADINGS DIFFERENT COLOURS - No Plugin - Jquery function =========================
	
	$('div.homepage_shout_box h3, h2.banner_offer_heading').each(function(){
		var me = $(this);
		me.html( me.text().replace(/([^\s]*)/,'<strong>$1</strong>') );
	});


//========================= SELECT 4th LIST ITEM AND ADD CLASS FOR PRODUCT LISTING COLOUR THUMBNAILS  - No Plugin - Jquery function =========================

	$('div#content ul.colours li:nth-child(4n)')
	.addClass('last').show();
	
	$('div#content ul.product_image_thumbs li:nth-child(4n)')
	.addClass('last').show();

	
//========================= HELP POP UPS ON PRODUCT PAGE and BASKET  - No Plugin - Jquery function =========================

	$('a.help_button').click(function() {
		var p = $(this).parent().find('div.help_pop_up').slideToggle('fast', function() {
			// Animation complete.
		});
	});	
	
	$('a.help_security_code').click(function() {
		var p = $(this).parent().parent().find('div.help_pop_up_security').slideToggle('fast', function() {
			// Animation complete.
		});
	});		
	

//========================= FANCY BOX POP UP FOE WELCOME VIDEO - Fancy Box - jquery.fancybox-1.3.1.js  =========================

	$("a#welcome_video").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		return false;
	});



// ======================= FOR PRODUCT LISTING PAGE FILTERS - No Plugin - Jquery function =========================
	
	$(".more_link").each(function () {
		var current = $(this);
		var currentTarget = $("#" + current.attr("moretarget") + ' ul.target')
		currentTarget.attr("slideheight", currentTarget.height());
		currentTarget.attr("slidestate", "close");
		if (currentTarget.height() > 205) {
			currentTarget.css("height", sliderHeight);

			current.bind(
                    "click",
                    function (e) {
                    	e.preventDefault();
                    	var current = $(this);
                    	var currentTarget = $("#" + current.attr("moretarget") + ' ul.target')
                    	if (currentTarget.attr("slidestate") == "close") {
                    		var open_height = currentTarget.attr("slideheight") + "px";
                    		currentTarget.animate({ "height": open_height }, 500, function () {
                    			current.html('less...');
                    		});
                    		currentTarget.attr("slidestate", "open");

                    	} else {
                    		currentTarget.animate({ "height": sliderHeight }, 500, function () {
                    			current.html('more...');
                    		});
                    		currentTarget.attr("slidestate", "close");
                    	}
                    }
                );
		} else {
			current.hide();
		}
	});

	$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' });
	


});
