$(document).ready(function(){
	$(".inner_products .inner_1 .inner_2 .inner_3 .main .product-wrap .products div.sale").each(function(){
		$(this).find("a:nth-child(1) img").after("<img src='http://www.popcreativestudio.co.uk/curteis/sale.png' class='sale1'>");
	});

	$(".featured-table .row .sale .featured_main_image").each(function(){
		$(this).after("<img src='http://www.popcreativestudio.co.uk/curteis/sale.png' class='sale2'>");
	});

	function ie_fix_slider(el, type){
		if( el.attr('id') == 'iefixslider' && $.browser.msie && $.browser.version == 7.0 || el.attr('id') == 'iefixslider' && $.browser.msie && $.browser.version == 6.0 ){
			if(type == 'show'){
				el.parent().find('#slider-range').slideDown();
			}else{
				el.parent().find('#slider-range').slideUp();
			}
		};
	};
	
	/* (1) IM NOT SURE YOUR ECOMMERCE SOFTWARE CAN INCLUDE FILES, IFRAMES AINT THE BEST METHOD, SO USE AN AJAX CALL FOR THE HOME BLOG BOX */
	/*$.get('http://popcreativestudio.co.uk/curteis/inspired/_home_articles.php', function(e){
		$("#blog_wrap").empty().append(e);
	});*/
	
	/* FOR NAVI DROPS */
	$(".navi li").hover(function(){
		$(this).find("div.drop").show();
	},function(){
		$(this).find("div.drop").hide();
	});
	
	/* FOR FILTER MAGIC DISAPPEARING BOXES */
	$(".inner_products .inner_1 .inner_2 .inner_3 .filter_controls .box h2").toggle(function(){
		ths = $(this);
		ie_fix_slider(ths, 'hide');
		el = ths.parent().find('div.selection_wrap');
		el.attr('rel', el.height() ).animate({height:0, marginBottom:0});
		ths.css({"background-position": "0px -12px"});
	},function(){
		ths = $(this);
		ie_fix_slider(ths, 'show');
		el = ths.parent().find('div.selection_wrap');
		el.animate({height: el.attr('rel') , marginBottom:15}).removeAttr('rel');
		ths.css({"background-position": "0px 2px"});
	});
	
	/* PRICE SLIDER */
	$(".inner_products .inner_1 .inner_2 .inner_3 .filter_controls .box .selection_wrap #slider-range").slider({
		range: true, min: 0, max: 500, values: [0, 500],
		slide: function(event, ui) {
			h1el = $(".inner_products .inner_1 .inner_2 .inner_3 .filter_controls .box .selection_wrap .handle1val"); // Handle1 element
			h2el = $(".inner_products .inner_1 .inner_2 .inner_3 .filter_controls .box .selection_wrap .handle2val"); // Handle2 element
			h1v = ui.values[0]; // Handle1 value
			h2v = ui.values[1]; // Handle2 value
			h1el.val( h1v+" mm" ); // Append value to element
			h2el.val( h2v+" mm" ); // Append value to element
		}
	});
	
	$("#wrap .body .inner_product .inner_1 .inner_2 .inner_3 .main .product-view .product-canvas img").draggable();
	
	// Added 2-8-11
	
	function loadTicker(){
		$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.curteis.com%2Fwordpress%2F%3Ffeed%3Drss2%22%20limit%204&format=json&diagnostics=true&callback=?",function(data){
			
			ticker = $('#js-news');
			ticker.empty();
			
			$.each(data.query.results.item,function(){
				//console.log(this);
				// $output = "<li class='news-item'><a href='" . $link . "'>" . $desc . " ... <span>" . $date . "</span></a></li>";
				
				tag = "<li class='news-item'><a href='" + this.link + "'>" + strip_tags(this.description).substr(0,105) + " ... <span>" + date("g:i a F j, Y", strtotime(this.pubDate)) + "</span></a></li>";
				ticker.append(tag);
			});
			
			ticker.ticker({
				pauseOnItems:4000,
				speed:0.2
			});
			
		})
	}
	if ($('#js-news').length) {
            loadTicker();
        }
		
	function preloadBannerCycle(){
		var banner = $("#big_banner div.big_banner_inner");
		var loader = $("#big_banner_loader");
                
		$.getJSON("../f0001/main.aspx?page=datalines&table=maingroup&filter=%7Bparentnumber%7D%3D30006&output=JSON", function(data){
			var imageURLS = [];
			var URLS = [];
                        var title = [];
			$.each(data, function()
                        {
				URLS.push(this.URL);
				imageURLS.push(this.picturefile);
                                title.push(this.name);
                        });
			$.imgpreload(imageURLS,{
				all: function(){
					$.each(imageURLS, function(i){
						banner.append( "<a href='"+URLS[i]+"'><img src='"+imageURLS[i]+"' title='" + title[i] + "' alt='" + title[i] + "'></a>" );
					});
					loader.remove();
					banner.cycle({
						fx:'scrollLeft',
						timeout:6000,
						speed:1100
					});
				}
			});
		});
	}
        if ($('#big_banner').length) {
            preloadBannerCycle();
        }
		
	function preloadBottomBanners(){
		$.getJSON("../f0001/main.aspx?page=datalines&table=maingroup&filter=%7Bparentnumber%7D%3D30005&output=JSON", function(data){
			
                        var imageURLS = [];
			var URLS = [];
                        var title = [];
			$.each(data, function()
                        {
				imageURLS.push(this.picturefile);
				URLS.push(this.URL);
                                title.push(this.name);
			});
			$.imgpreload(imageURLS,{
				all: function(){
					$("#bottom_banners .banner_a").empty().append( "<a href='" + URLS[0] + "'><img src='" + imageURLS[0] + "' title='" + title[0] + "' alt='" + title[0] + "'></a>" );
					$("#bottom_banners .banner_b").empty().append( "<a href='" + URLS[1] + "'><img src='" + imageURLS[1] + "' title='" + title[1] + "' alt='" + title[1] + "'></a>" );
					$("#bottom_banners .banner_c").empty().append( "<a href='" + URLS[2] + "'><img src='" + imageURLS[2] + "' title='" + title[2] + "' alt='" + title[2] + "'></a>" );
					$("#bottom_banners .banner_d").empty().append( "<a href='" + URLS[3] + "'><img src='" + imageURLS[3] + "' title='" + title[3] + "' alt='" + title[3] + "'></a>" );
				}
			});	
		});
	}
        if ($('#bottom_banners').length) {
            preloadBottomBanners();
        }
	
});

