/* ------------------------------------------------------------------------------------
Website: Keep Britain Tidy bin bags microsite
File: Javascript (jquery)
Author: Reading Room
Created: Sept 2009
------------------------------------------------------------------------------------ */
$(document).ready(function() {

/* ------------------------------------------------------------------------------------
-- Heading replacements
------------------------------------------------------------------------------------ */
	if (jQuery.browser.msie) {
		$("h2, h3").each( function(){
			$(this).html("&nbsp;" + $(this).html()).css("margin-left","-.3em");
		});
	}
	Cufon.replace('h1, h2, h3');

/* ------------------------------------------------------------------------------------
-- PNG fixes (uses DD_roundies not DD_pngfix, as it's already present for rounded corners)
------------------------------------------------------------------------------------ */
	DD_roundies.addRule('.vote, ul.popularDesigns li div, #contentTopBinbag, #contentBinbag, #contentBottomBinbag, .infiniteCarousel li, .infiniteCarousel .arrow, .listing li div, .btn img, #binBagLogo img, #binBag');

/* ------------------------------------------------------------------------------------
-- Rounded corners
------------------------------------------------------------------------------------ */
	if (($.browser.msie) && ($.browser.version == "6.0")){
		//stupid ie 6 doesn't get rounded corners for now
	} else {
		DD_roundies.addRule('.popup', 10, true);
	}
	DD_roundies.addRule('.roundedBox', 10, true);

/* ------------------------------------------------------------------------------------
-- Fix listing page layouts when names are on two lines
------------------------------------------------------------------------------------ */
	$(".listing li:eq(5), .listing li:eq(10)").css("clear","left");

/* ------------------------------------------------------------------------------------
-- Create back links
------------------------------------------------------------------------------------ */
	$("#back").append("<a href=\"javascript:history.go(-1)\">[&nbsp;back&nbsp;]</a>")

/* ------------------------------------------------------------------------------------
-- Make whole bin bag items clickable
------------------------------------------------------------------------------------ */
	$(".infiniteCarousel li").click( function(){
		document.location.href = $(this).find("a").attr("href");
		return false;
	}).each( function(){
		$(this).css("cursor","pointer")
	});
	$(".listing li div").click( function(){
		document.location.href = $(this).find("p a").attr("href");
		return false;
	}).each( function(){
		$(this).css("cursor","pointer")
	});
	
/* ------------------------------------------------------------------------------------
-- Flash map
------------------------------------------------------------------------------------ */
    $('#flashDesigner').flash(
        { 
          src: '/images/flash/KBT_preloader.swf',
          width: 740,
          height: 670,
		  wmode:"transparent",
          flashvars: {fileLocation: "/images/flash/KBT.swf", termsConditions:"/BinBag/terms-and-conditions.aspx" }
        },
        { version: 10 }
    );

/* ------------------------------------------------------------------------------------
-- In-page popups
------------------------------------------------------------------------------------ */

	$(".popup").addClass("popupJs") //we've got javascript
		.hide() //hide them on load
		.find(".btn").append("<a class=\"cancel\" href=\"#\">Cancel</a>"); //add the 'cancel' link
	
	$("a[href='#vote']").click( function(){
		$(".popup").hide();//hide other popups
		$("#vote").fadeIn();
		$(this).blur()
		//return false;
	});
	$("#vote .btn a.cancel").click( function(){
		$("#vote").fadeOut();
		return false;
	});
	
	$("a[href='#sendToFriend']").click( function(){
		$(".popup").hide();//hide other popups
		$("#sendToFriend").fadeIn();
		$(this).blur()
		//return false;
	});
	$("#sendToFriend .btn a.cancel").click( function(){
		$("#sendToFriend").fadeOut();
		return false;
	});
	// open Vote popup on load
	pageURL=String(document.location);
	if(pageURL.indexOf("#vote")!=-1){
		$("#vote").show();
	}

/*
	$(".popup").addClass("popupJs") //we've got javascript
		.css("left","-9999em")
		.find(".btn input").after("<a class=\"cancel\" href=\"#\">Cancel</a>"); //add the 'cancel' link
	
	$("a[href='#vote']").click( function(){
		$(".popup").css("position","absolute").css("left","-9999em");
		$("#vote").css("left","190px")
		$(this).blur()
	});
	$("#vote .btn a.cancel").click( function(){
		$("#vote").css("left","-9999em")
		return false;
	});
	
	$("a[href='#sendToFriend']").click( function(){
		$(".popup").css("left","-999em");//hide other popups
		$("#sendToFriend").css("left","190px")
		$(this).blur()
	});
	$("#sendToFriend .btn a.cancel").click( function(){
		$("#sendToFriend").css("left","-9999em")
		return false;
	});
	// open Vote popup on load
	pageURL=String(document.location);
	if(pageURL.indexOf("#vote")!=-1){
		$("#vote").css("left","190px");
	}
*/

/* ------------------------------------------------------------------------------------
-- Social networking share links
------------------------------------------------------------------------------------ */
//	$("#facebook a").click( function(){
//		return fbs_click()
//	});
//	$("#facebook a, #twitter a").each( function(){
//		$(this).attr("target","_blank")
//	})

	
/* --------------------------------------------------------------------------------- */
});


/* ------------------------------------------------------------------------------------
-- Functions (outside jquery block)
------------------------------------------------------------------------------------ */
function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
