// JavaScript Document

// Global Variables
var pos=1;
var pathname = window.location.pathname;

function breadcrumbs(){
	if(pathname.substr(0,15) == "/_product_82058") {
		output = '<a href="/">BikiniThief.com</a> / <a href="/_catalog_82058/Collection">Collection</a> / '+document.title;
	} else if(pathname.substr(0,15) == "/_product_82060") {
		output = '<a href="/">BikiniThief.com</a> / <a href="/_catalog_82060/Maternity">Maternity</a> / '+document.title;
	} else if(pathname.substr(0,15) == "/_product_94298") {
		output = '<a href="/">BikiniThief.com</a> / <a href="/_catalog_94298/Accessories">Accessories</a> / '+document.title;
	} else if(pathname == "/_blog/Bikini_Thief_Blog" || pathname.substr(24,5) == "/page") {
		output = '<a href="/">BikiniThief.com</a> / News';
	} else if(pathname.substr(24,5) == "/post") {
		output = '<a href="/">BikiniThief.com</a> / <a href="/_blog/Bikini_Thief_Blog">News</a> / '+document.title;
	} else if(pathname.substr(0,21) == "/orderretrievev2.aspx") {
		output = '<a href="/">BikiniThief.com</a> / Shopping Cart';
	} else if(pathname.substr(0,21) == "/OrderRetrievev2.aspx") {
		output = '<a href="/">BikiniThief.com</a> / <a href="/orderretrievev2.aspx">Shopping Cart</a> / Checkout';
	}else {
		switch(pathname){
		case '/':
			output = "Aloha!";
			break;
		case '/_catalog_82058/Collection':
			output = '<a href="/">BikiniThief.com</a> / Collection';
			break;
		case '/_catalog_82060/Maternity':
			output = '<a href="/">BikiniThief.com</a> / Maternity';
			break;
		case '/_catalog_94298/Accessories':
			output = '<a href="/">BikiniThief.com</a> / Accessories';
			break;
		case '/_product_94299/Bikini_Thief_Gift_Card':
			output = '<a href="/">BikiniThief.com</a> / Gift Card';
			break;
		default:
			output = '<a href="/">BikiniThief.com</a>';
			break;
		}
	}
	document.write(output);
}


jQuery.fn.fadeToggle = function(speed, easing, callback) { 
   return this.animate({opacity: 'toggle'}, speed, easing, callback); 
};


blogSpan = function() {
	var blogID="blog-"+pos;
	if (pathname == "/" || pathname == "/_blog/Bikini_Thief_Blog" || pathname.substr(24,5) == "/page") {
		switch(pos) 
		{
		case 1:
  		  spanClass="span-8";
		  break;
		case 2:
  		  spanClass="span-11";
  		  break;
		case 3:
			if(pathname == "/") {
	  		  spanClass="span-5 last home3";
			} else {
			  spanClass="span-5 last";
			}
  		  break;
		case 4:
		  spanClass="clear span-11";
		  break;
		case 5:
		  spanClass="span-13 last";
		  break;
		case 6:
		  spanClass="clear span-8";
		  break;
		case 7:
		  spanClass="span-11";
		  break;
		case 8:
		  spanClass="span-5 last";
		  break;
		case 9:
		  spanClass="clear span-13";
		  break;
		case 10:
		  spanClass="span-11 last";
		  break;
		}
		pos++;
	} else {
		spanClass="span-22 push-1";
	};
	document.write('<div class="blog-post '+spanClass+'" id="'+blogID+'">');
};

onLoadfunc = function() {
//Set Width of Blog List Article Text and Apply ThreeDots
	for(n=1;n<=10;n++){
		$(".bt-blogpostlist #blog-"+n+" .bt-postbody").width($("#blog-"+n+" .bt-postbody").width());
		$(".bt-blogpostlist #blog-"+n+" .bt-postbody").ThreeDots({ellipsis_string:'&#8230;',max_rows:8});
	}

	//Blogpost Header Creation
	var pathname = window.location.pathname;
	if (pathname.substr(24,5) == "/post") {
		var cache = $('img.thumbnail').clone().removeClass('thumbnail').addClass('Image1').css('float','left');
		$('img.thumbnail').remove();
		$('#dynHeader').append(cache);
		var ratio = (cache.width() / cache.height());
		var imageHeight = $('#dynHeader').height();
		var imageWidth = (imageHeight*ratio);
		cache.height(imageHeight).width(imageWidth);
		var remainWidth = $('#dynHeader').width() - imageWidth;
		var dupe = cache.clone();
		if(ratio<=1){
			dupe.removeClass('Image1').addClass('Image2').css("width",remainWidth+"px").css("height","auto");
			cache.after(dupe);
		} else {
			dupe.removeClass('Image1').addClass('Image2').css("width","auto").css("height",imageHeight);	
		};
	} else if (pathname.substr(0,9) == "/_catalog") {
		$('#catalogImage').css('display','block');
	};
};

onReadyfunc = function() {
	
	//Add back view to shopping cart page
	$(".cartImage .productitemcell img").each(function() {
		var thumb = $(this).clone().addClass('back').attr('src', $(this).attr('src').replace('.jpg','-back.jpg'));	
		$(this).parent().append(thumb);
	});
	
	//ToolTip
    $(".tooltip[title]").tooltip({
		effect: "fade",
		tip: "#tooltip"
	}); 
	//Checkout Form Tooltip
		$("#orderContact :input, #shippingInfo :input, #billingInfo :input, .giftvoucher-reg :input").tooltip({ 
    		position: "top center", 
    		effect: "fade",  
    		tip: '#tooltip' 
		});

	//iFrame Properties
	$(".iframe a, a.iframe").fancybox({
		'width'				: 950,
		'height'			: '80%',
	    'autoScale'     	: true,
	    'transitionIn'		: 'linear',
		'transitionOut'		: 'linear',
		'type'				: 'iframe',
		'overlayColor'		: '#F49AC1',
		'overlayOpacity'	: '0.9'
	});
	
	//Fancybox Bikini in Motion
	$("#motion").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'linear',
			'transitionOut'	: 'linear',
			'overlayColor'	: '#F067A6',
			'overlayOpacity': '0.8',
			'title'			: this.title,
			'width'			: 720,
			'height'		: 405,
			'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
			'type'			: 'swf',
			'swf'			: {
		   		'wmode'		: 'transparent',
		'allowfullscreen'	: 'true'
		}
	});

	return false;
});

	
	// Auto-Collapse Home Page Panel
	pathname = window.location.pathname;
	if (pathname == "/") {
		$("#close-btn").fadeToggle("slow");
		$("#panel").slideToggle("slow");
		$(".btn-slide").toggleClass("active");
		$("#panel div.announcement").fadeToggle("slow");
	
		var timer = setTimeout( function(){
			$("#panel").slideToggle("slow");
			$(".btn-slide").toggleClass("active");
			$("#panel div.announcement").fadeToggle("slow");
			$("#close-btn").fadeToggle("slow");
    	}, 5000 );
	};
	
	// Toggle Panel
	$(".btn-slide").click(function(){
		clearTimeout(timer);
		//$(".btn-slide").addClass("active");
	  	$("#panel").slideToggle("slow");
		$(".btn-slide").toggleClass("active");
		$("#panel div.announcement").fadeToggle("slow");
		$("#close-btn").fadeToggle("slow");
	});
	
	// Collapse Panel Button
	$("#close-btn").click(function(){
		clearTimeout(timer);
		$("#panel").slideUp("slow");
		$(".btn-slide").toggleClass("active");
		$("#panel div.announcement").fadeToggle("slow");
		$("#close-btn").fadeToggle("slow");	
	});
	
	// Collapse Panel Button Mouse Over Image
	$(".close-btn").hover(function() {
			this.src = this.src.replace("_off","_on");
		}, function() {
			this.src = this.src.replace("_on","_off");
	});	
	
	// Product Page Large Image Swap
	var swap = false;
	$("#altView").click(function() {
		var t=$("#mainImage img");
		var a=$("#altView img");
		if(swap){
			t.attr('src',t.attr('src').replace("-back", "-front"));
			a.attr('src',a.attr('src').replace(".jpg","-back.jpg"));
			swap = false;
		} else {
			t.attr('src',t.attr('src').replace("-front", "-back"));
			a.attr('src',a.attr('src').replace("-back",""));
			swap = true;
		};
	});

	//Check pathname - Home page blog, or other.
	if (pathname == "/" || pathname == "/_blog/Bikini_Thief_Blog" || pathname.substr(24,5) == "/page") {
		//Creat the blog list thumbnail images
		for(x=1;x<=10;x++){
        	$("#blog-"+x+" div.post-thumb").append( $("#blog-"+x+" div.post-body img.thumbnail") );
		};
		//Display .mouseOver (read more) on the Blog List
		
		$(".blog-post").hover(function(){
			var divWidth = $(this).width();
			var divHeight = $(this).height();
  			$(this).find(".mouseOver").css("width",divWidth-20+"px");
			$(this).find(".mouseOver").css("height",divHeight-20+"px");
 			$(this).find(".mouseOver").fadeTo('normal', 0.8); 
			var el=this;
  			setTimeout( function(){
    			$(el).find(".mouseOver").fadeOut();
    		}, 750 );
		}, function() { 
			$(this).find(".mouseOver").fadeOut();
 		});
 		
		$(".blog-post").click(function(){
	  		window.location=$(this).find("a").attr("href"); return false;
		});		
		//Set class of #bt-blog to .bt-blogpostlist
		var n=document.getElementById('bt-blog');
		if(n) {
    		n.className+=n.className?' bt-blogpostlist':'bt-blogpostlist';
		}
	} else {
		//Do not display .mouseOver (read more) because its not the list page
		$(".mouseOver").css("display","none");
		//Set class of #bt-blog to .bt-blogpost
  		var n=document.getElementById('bt-blog');
		if(n) {
    		n.className+=n.className?' bt-blogpost':'bt-blogpost';
		}
		//Set title attribute for Captcha
		$('#CaptchaV2').attr('title', 'Enter Text on Left').removeAttr('style').addClass('span-8').addClass('last').addClass('commentBox');
		//Comment Form Tooltip
		$("#comment-form :input").tooltip({ 
    		position: "top center", 
    		effect: "fade",  
    		tip: '#tooltip' 
		});
	}
  	
	//Only Display Home Page header image if on the homepage
	if (pathname != "/") {
  		$("#webappImage").css("display","none");
  	};
	
	//Display .mouseOver (read more) on the Blog List
	/*
	$(".smallProduct").hover(function(){
		var divWidth = $(this).width();
  		$(this).find(".mouseOver").css("width",divWidth-20+"px");
 		$(this).find(".mouseOver").fadeTo('normal', 0.8); 
		var el=this;
  		setTimeout( function(){
    		$(el).find(".mouseOver").fadeOut();
    	}, 750 );
	}, function() { 
		$(this).find(".mouseOver").fadeOut();		 
 	});
 	*/
	$(".smallProduct").click(function(){
		window.location=$(this).find("a").attr("href"); return false;
	});
};

//Perform these tasks after all images load
$(window).load(function(){
	onLoadfunc();
});

//Perform these tasks as soon as the Document is ready
$(document).ready(function(){
	onReadyfunc();
 });  
