 var frutiger47Lcn = {
  src: '/global/swf/Frutiger47LCn.swf'
  ,ratios: [10, 1.32, 16, 1.27, 23, 1.23, 24, 1.21, 25, 1.22, 31, 1.21, 38, 1.2, 42, 1.19, 43, 1.2, 51, 1.19, 55, 1.18, 56, 1.19, 94, 1.18, 98, 1.17, 100, 1.18, 104, 1.17, 105, 1.18, 110, 1.17, 111, 1.18, 1.17]
};
 var Frutiger47CnGlow = {
  src: '/global/swf/Frutiger47CnGlow.swf'
  ,ratios: [10, 1.32, 16, 1.27, 23, 1.23, 24, 1.21, 25, 1.22, 31, 1.21, 38, 1.2, 42, 1.19, 43, 1.2, 51, 1.19, 55, 1.18, 56, 1.19, 94, 1.18, 98, 1.17, 100, 1.18, 104, 1.17, 105, 1.18, 110, 1.17, 111, 1.18, 1.17]
};
 var arialce = {
  src: '/global/swf/ArialCE.swf'
  ,ratios: [8, 1.3, 12, 1.27, 16, 1.21, 19, 1.17, 24, 1.18, 26, 1.16, 27, 1.17, 35, 1.16, 44, 1.15, 63, 1.14, 64, 1.13, 67, 1.14, 68, 1.13, 70, 1.14, 76, 1.13, 77, 1.14, 1.13]
};

 var frutiger57cn = {
  src: '/global/swf/Frutiger57Cn.swf'
  ,ratios: [8, 1.41,11, 1.31, 15, 1.29, 21, 1.25, 22, 1.22, 27, 1.24, 28, 1.23, 34, 1.22, 46, 1.21, 50, 1.2, 51, 1.21, 70, 1.2, 72, 1.19, 74, 1.2, 78, 1.19, 79, 1.2, 83, 1.19, 84, 1.2, 1.19]
};


sIFR.activate(frutiger47Lcn);
sIFR.activate(arialce);
sIFR.activate(Frutiger47CnGlow);
sIFR.activate(frutiger57cn);
//sIFR.activate(arialglow);
//sIFR.debug.ratios({ src: '/global/swf/Frutiger47CnGlow.swf', selector: 'div.cta div.body span' });

sIFR.replace(frutiger47Lcn, {
	selector: 'h1 span.black',
	css: [
        '.sIFR-root { color: #0E1622; font-weight: bold; text-transform: uppercase;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'h1 span.orange',
	css: [
        '.sIFR-root { color: #C16532; font-weight: bold; text-transform: uppercase;}'
      ]
});
sIFR.replace(arialce, {
	selector: 'div.sidemenu h3',
	css: [
        '.sIFR-root { color: #325079; font-weight: bold; text-transform: uppercase;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'div.search div.heading h3',
	css: [
        '.sIFR-root { color: #ffffff; font-weight: bold; text-transform: uppercase;}'
      ]
});

sIFR.replace(frutiger47Lcn, {
	selector: 'div.menu ul.main-menu li.active span',
	css: [
        '.sIFR-root {text-align: center;  text-transform: uppercase;}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #325079; font-weight: bold;}'
        ,'a:hover { color: #325079;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'div.menu ul.main-menu li span',
	css: [
        '.sIFR-root {text-align: center;  text-transform: uppercase;}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #C6652F; font-weight: bold;}'
        ,'a:hover { color: #325079;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'div.tabs ul li.active span.start',
	css: [
        '.sIFR-root {}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #1e222b; font-weight: bold;}'
        ,'a:hover { color: #1e222b;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'div.tabs ul li span.start',
	css: [
        '.sIFR-root {}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #D2D3D5; font-weight: bold;}'
        ,'a:hover { color: #ffffff;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'div.smalltabs ul li.active span',
	css: [
        '.sIFR-root {}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #1e222b; font-weight: bold; text-align: center;}'
        ,'a:hover { color: #1e222b;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'div.smalltabs ul li span',
	css: [
        '.sIFR-root {}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #EDEEEF; font-weight: bold; text-align: center;}'
        ,'a:hover { color: #ffffff;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: 'div.even-split-boxes div.box p.dwnl-btn',
	css: [
        '.sIFR-root {text-align: left;  text-transform: uppercase;}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #325079; font-weight: bold;}'
        ,'a:hover { color: #c6652f;}'
      ]
});

/*homepage sifrs*/
sIFR.replace(frutiger57cn, {
	selector: 'div.features div.feature div.head div.heading h3',
	css: [
		'.sIFR-root{color: #3a4151; font-weight: bold;}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #3a4151; font-weight: bold;}'
        ,'a:hover { color: #C6652F;}'
	  ]
});
sIFR.replace(Frutiger47CnGlow, {
	selector: 'div.cta div.body span',
	css: [
        '.sIFR-root {text-transform: uppercase;}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #ffffff; font-weight: bold;}'
        ,'a:hover { color: #ffffff;}'
      ]
});

/*popup specific sifr's*/
sIFR.replace(frutiger47Lcn, {
	selector: '.media-popup .finishes h3',
	css: [
        '.sIFR-root { color: #FFFFFF; font-weight: bold; text-transform: uppercase;}'
      ]
});
sIFR.replace(frutiger47Lcn, {
	selector: '.media-popup .tours h3',
	css: [
        '.sIFR-root { color: #636974; font-weight: bold; text-transform: uppercase;}'
      ]
});
sIFR.replace(Frutiger47CnGlow, {
	selector: '.media-popup .tours .vt-nav ul li.selected',
	css: [
        '.sIFR-root {text-transform: uppercase;}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #ffffff; font-weight: bold;}'
        ,'a:hover { color: #ffffff;}'
      ]
});
sIFR.replace(Frutiger47CnGlow, {
	selector: '.media-popup .tours .vt-nav ul li',
	css: [
        '.sIFR-root {text-transform: uppercase;}'
        ,'a { text-decoration: none;}'
        ,'a:link { color: #a9abb2; font-weight: bold;}'
        ,'a:hover { color: #ffffff;}'
      ]
});


jQuery(document).ready(function(){
	
	$("body").addClass("jsEnabled");
	
	Shadowbox.init({
	    language: 'en',
	    players:  ['html', 'iframe', 'img']
	});
	
	//homepage rotator
	if(document.getElementById("home-rotator"))
	{
		xmlpath = $("#home-rotator").attr("rel");
		var so = new SWFObject("/global/swf/devine-main-rotator.swf", "rotator", "767", "293", "9", "#000000");
		so.addParam("wmode", "transparent");
		so.addVariable("xml", xmlpath);
		so.write("home-rotator");
	}
	
	//carousel fader
	jQuery("div.full-fader div.image-fader").ImageFader({autoScroll: true, autoScrollTimeDelay: 4000});
	jQuery("div.partial-fader div.image-fader").ImageFader({autoScroll: true, autoScrollTimeDelay: 4000});
	jQuery("div.mini-fader div.image-fader").ImageFader();
	
	//smalltabs hover class
	$("div.smalltabs ul li").hover(
		function()
		{
			if($(this).attr("class").match("first"))
			{
				$(this).addClass("first-hover");
			}
			else if($(this).attr("class").match("last"))
			{
				$(this).addClass("last-hover");
			}
			else
			{
				$(this).addClass("hover");
			}
		},
		function()
		{
			if($(this).attr("class").match("first"))
			{
				$(this).removeClass("first-hover");
			}
			else if($(this).attr("class").match("last"))
			{
				$(this).removeClass("last-hover");
			}
			else
			{
				$(this).removeClass("hover");
			}
		}
	);
	
	//sidenav hover behaviour
	$("div.sidemenu ul").hover(
		function()
		{
			//remove the active class from the current active item and place in a holder class
			$(this).children("li.active").addClass("curr-active").removeClass("active");
		},
		function()
		{
			//place active class back on the current active item and remove holder class
			$(this).children("li.curr-active").addClass("active").removeClass("curr-active");
		}
	);
	
	//Flash minisite shadowboxes
	$("a.flash-mini").click(
		function()
		{
			//scroll to top of the browser window.
			window.scroll(0,0);
			
			swfloc = $(this).attr("href");
			xmlloc = $(this).attr("rel");
			Shadowbox.open({
				player:     'html',
				content: 	'<div id="flash-mini"></div>',
				height:     558,
				width:      882,
				options:    {
					onFinish: function(item)
					{
						//inject minisite markup into the shadowbox
						$("#sb-info").css("overflow", "visible");
						$("#sb-title").css("overflow", "visible");
						$("#sb-info-inner").prepend('<div class="shadowbox-footer">&copy; 2008 Devine Limited  |   <a href="/privacy-policy.aspx">Privacy Policy</a></div><img src="/global/img/logo-shad-devine.gif" alt="Devine Logo" class="footer-logo" />');
						$("#sb-title").prepend('<a href="javascript:Shadowbox.close();" class="sb-close"><span class="hidden">Close</span></a>')
						//put in the swf
						//global/swf/apartments/charlottetowers/carveonlydata.xml
						
						var so = new SWFObject(swfloc, "sotester", "882", "558", "9", "#000000");
						so.addParam("wmode", "transparent");
						so.addVariable("passed", xmlloc);
						so.write("flash-mini");
					}
				}
			});
		
			return false;
		}
	);
	//Form shadowboxes
	//set up
	$("a.form-popup").each(
		function()
		{
			//swap href and rel
			href = $(this).attr("href");
			rel = $(this).attr("rel");
			$(this).attr("href", rel);
			$(this).attr("rel", href);
		}
	);
	//behaviour
	$("a.sb-close").click(function(){parent.Shadowbox.close(); return false;})
	$("a.reg-int").click(
		function()
		{
			//scroll to top of the browser window.
			window.scroll(0,0);
			
			if($(this).attr("class").match("form-popup"))
			{
				href = $(this).attr("href");
				
				Shadowbox.open({
					player:     'iframe',
					content: 	href,
					height:     629,
					width:      652
				});
		
				return false;
			}
			else
			{
				return true;
			}
		}
	);
	$("a.send-friend").click(
		function()
		{
			//scroll to top of the browser window.
			window.scroll(0,0);
			
			if($(this).attr("class").match("form-popup"))
			{
				href = $(this).attr("href");
				
				Shadowbox.open({
					player:     'iframe',
					content: 	href,
					height:     484,
					width:      654
				});
		
				return false;
			}
			else
			{
				return true;
			}
			
		}
	);
	/*media shadowboxes*/
	$("a.media-popup-finishes").click(
		function()
		{
			window.scroll(0,0);
			
			href = $(this).attr("href");
			//create temp markup holder
			$("body").append("<div id='temp-holder' class='hidden'></div>");
			var markup;
			$("#temp-holder").load(href+" .media-popup", function()
			{
				markup = $("#temp-holder").html();
				$("#temp-holder").remove();
				
				Shadowbox.open({
					player:     'html',
					content: 	markup,
					height:     586,
					width:      754,
					options:    {
						onFinish: function(item)
							{
								$("a.sb-close").click(function(){parent.Shadowbox.close(); return false;});
								sIFR.replace(frutiger47Lcn, {
									selector: '.media-popup h3',
									css: [
								        '.sIFR-root { color: #FFFFFF; font-weight: bold; text-transform: uppercase;}'
								      ]
								});							
								draggableImage($(".dragImage"));
								
							}
						}
				});
				
			});
			
			return false;
		}
	);
	$("a.media-popup-tours").click(
		function()
		{
			window.scroll(0,0);
			
			href = $(this).attr("href");
			
			
			Shadowbox.open({
				player:     'iframe',
				content: 	href,
				height:     506,
				width:      774
			});
				
			
			return false;
		}
	);
	$("a.view-display-home").click(
		function()
		{
			parent.window.location = $(this).attr("href");
			return false;
		}
	);
	/*image shadowboxes*/
	$("a.shadowbox-img").click(
		function()
		{
			//scroll to top of the browser window.
			window.scroll(0,0);
			
			imgsrc = $(this).attr("href");
			wh = $(this).attr("rel");
			ind1 = wh.indexOf("width=");
			ind2 = wh.indexOf(";");
			w = wh.substring(ind1+6, ind2);
			ind1 = wh.indexOf("height=");
			ind2 = wh.indexOf(";", ind2+1);
			if(ind2 < 1)
			{
				ind2 = wh.length;
			}
			h = wh.substring(ind1+7, ind2);
			w = parseInt(w) +8;
			h = parseInt(h) +8;
			
			html = '<img src="'+imgsrc+'"/>';
			
			Shadowbox.open({
				player: 	'img',
				content: 	imgsrc,
				height: 	h,
				width: 		w,
				options:    {
					onFinish: function(item)
					{
						$("#sb-info").css("overflow", "visible");
						$("#sb-title").css("overflow", "visible");
						$("#sb-title").prepend('<a href="javascript:Shadowbox.close();" class="sb-close"><span class="hidden">Close</span></a>');
					},
					onOpen: function(item)
					{
						$("#sb-body").addClass("sb-body-inner-img");
					},
					onClose: function(item)
					{
						$("#sb-title a.sb-close").remove();
						$("#sb-body").removeClass("sb-body-inner-img");
					}
				}
			});
			
			return false;
		}
	);
				
	/*ie6 hover classes*/
	$("div.cta div.body div.wrapper").hover(
		function()
		{
			$(this).addClass("wrapper-hover").addClass("ie6-hover");
		},
		function()
		{
			$(this).removeClass("wrapper-hover");
		}
	);
	$("input.btn-search").hover(
		function()
		{
			$(this).addClass("btn-hover");
		},
		function()
		{
			$(this).removeClass("btn-hover");
		}
	);
	$("input.btn-submit").hover(
		function()
		{
			$(this).addClass("btn-submit-hover");
		},
		function()
		{
			$(this).removeClass("btn-submit-hover");
		}
	);
	$("input.btn-send").hover(
		function()
		{
			$(this).addClass("btn-send-hover");
		},
		function()
		{
			$(this).removeClass("btn-send-hover");
		}
	);

	$(".dragImage").each(
		function()
		{
			draggableImage($(this));
		}
	);

	//expander behaviour
	$("div.expanders div.exp-header h3 a").hover(
		function()
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);
	
	//prepare the exp-body divs for animate
	$("div.expanders div.exp-body").css("display", "none").removeClass("hidden");
	$("div.expanders div.exp-body:first").css("display", "block");
	
	$("div.expanders div.exp-header h3 a").click(
		function()
		{
			toopenid = $(this).attr("href").replace("#", "");
			tocloseid = $(this).parents(".expanders").children(".exp-header").children("h3.open").children("a").attr("href").replace("#", "");
			
			//animate
			$("#"+tocloseid).slideUp("slow");
			$("#"+toopenid).slideDown("slow");
			
			//$("#"+tocloseid).css("display", "none").addClass("hideme");
			//$("#"+toopenid).css("display", "block").removeClass("hideme");
			
			//update open class
			$(this).parents(".expanders").children(".exp-header").children("h3.open").removeClass("open");
			$(this).parents("h3").addClass("open");
			
			return false;
		}
	);
	
});

function draggableImage(el)
{
	theimg = el.children(".scope").children("img");
	thecontrol = el.children(".scope").children(".drag-control");
	thescope = el.children(".scope");
	
	theimg.mousedown(
		function(e)
		{
			e.preventDefault();
		}
	);
	
	var flagMouseDown = false;
	var mousex;
	var mousey;
	var startx;
	var starty;
	var maxx = 0;
	var maxy = 0;
	var minx = thescope.width() - theimg.width();
	var miny = thescope.height() - theimg.height();
	//check for images smaller in width &/ height
	if(minx > 0)
	{
		//position the image horizontally centered
		newx = Math.round((thescope.width()/2) - (theimg.width()/2));
		theimg.css("left", newx+"px");
		maxx = minx = newx;
	}
	if(miny > 0)
	{
		//position the image vert centered
		newy = Math.round((thescope.height()/2) - (theimg.height()/2));
		theimg.css("top", newy+"px");
		maxy = miny = newy;
	}
	
	//if the image is large enough for the drag assign dragging behaviour
	if(!(minx == maxx && miny == maxy))
	{
		thecontrol.hover(
			function()
			{
				$(this).css("cursor", "move");
			},
			function()
			{
				$(this).css("cursor", "pointer");
			}
		);
		
		thecontrol.mousedown(
			function(e)
			{
				//flag mousedown
				flagMouseDown = true;
				
				startx = Math.round(e.pageX);
				starty = Math.round(e.pageY);
				
				e.preventDefault();
			}
		);
		
		$("body").mouseup(
			function(e)
			{
				//reset mousedown flag
				flagMouseDown = false;
			}
		);
		
		$("body").mousemove(
			function(e)
			{
				//if mousedown flagged then do behaviour
				if(flagMouseDown == true)
				{
					//get the current position of the img
		            currx = parseInt(theimg.css("left").replace("px", ""));
		            curry = parseInt(theimg.css("top").replace("px", ""));
		            //get the new mouse position
		            mousex = Math.round(e.pageX);
		            mousey = Math.round(e.pageY);
		            //find the diff
		            diffx = mousex - startx;
		            diffy = mousey - starty;
		            //get the new position
		            newx = currx + diffx;
		            newy = curry + diffy;
		            //check max positioning of the image
		            if(newx > maxx){newx = maxx;}
		            if(newy > maxy){newy = maxy;}
		            //check min positioning of the image
		            if(newx < minx){newx = minx;}
		            if(newy < miny){newy = miny;}
		            //assign the new position
		            theimg.css("left", newx+"px");
		            theimg.css("top", newy+"px");
		            //update the previous mouse position
		            startx = mousex;
		            starty = mousey;
					
				}
			}
		);
	}
}