﻿// IE6
var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand; 
try {if(!!m) {m("BackgroundImageCache", false, true);}}catch(e) {};

(function($) {

	$(function(){
		// PPC Check
		ppc.process();
		//megadrop
		if ($.fn.dropdown) {
			$('ul.mddTriggers').dropdown();
		}
		//login
		
		if ($.loginPanel) {
			$.loginPanel.init();
		}
		//tabs
		if ($.fn.tabs) {
			$('div.tabs').tabs({
				tabs: 'ul',
				node: 'div.tabContent',
				selected: 'selected'
			});
		};
		
		if($.fn.simplerotator){
			$('div.rotatingBanner').simplerotator({menu:'ul.control'})
									.bind('rotator.change',function(e,v,$p){
										if(!$p.find('p.heading-2').hasClass('sFIR-replaced')) {
											sIFR.replace(gillSans, {
												selector:	'div.contentStyle03c p.heading-2',
												css:		['.sIFR-root {font-size:15px; text-transform:uppercase;color:#ffffff;}'],
												tuneHeight:	'-6',
												wmode:		'transparent'
											});
										}
										if(!$p.find('h3').hasClass('sFIR-replaced')) {
											sIFR.replace(gillSans, {
												selector:	'div.contentStyle03c h3',  
												css:		['.sIFR-root {font-size:24px; color:#ffffff;}'],
												wmode:		'transparent'
											});
										}
									});		
		}

		if($.fn.accordion){
			// create accordion object
			$('div.contentStyle06a').accordion({
				node:'div.item',
				heading:'p.heading-2 a',
				content:'div.content',
				open:'open',
				forceClose:	false


			})
			/*$('div.contentStyle06a').accordion({
				node:'div.item',
				heading:'h2 a',
				content:'div.content',
				open:'open',
				forceClose: false,
				update:[{selector:'h2 a',text:['Collapse','Expand']}]
				});
			*/
			//$('div.contentStyle06a h2 a').click(function(){ 
			   //alert('click');
			//debugger;
			//var isOpen = $(this).parent().parent().hasClass("open");
			//alert(isOpen);
			//});
		}

	});



})(jQuery);

// 

var ppc = {
	process: function()
	{	
		var ppcvalue = ppc.getParameterByName( 'DCMP' );
		var PPCCookieName = "CouutsPPCReferer";
		if (ppcvalue != ""){
			ppc.createCookie(PPCCookieName, true, 2);
		}
		
		var CouttsCookie = null;
		var isPPCReferer = false;
		CouttsCookie = ppc.readCookie(PPCCookieName);
		if (CouttsCookie != null)
			isPPCReferer = eval(CouttsCookie);
			
		if (isPPCReferer){
			$("span.non-ppc-tel").hide();
			$("span.ppc-tel").show();
		}
		
	},
	getParameterByName: function( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return decodeURIComponent(results[1].replace(/\+/g, " "));
	},
	createCookie: function(name, value, days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else var expires = "";
		document.cookie = name + "=" + escape( value ) + expires + "; path=/";
	},
  createSecureCookie: function( name, value, days, path, domain, secure )
     {
		// set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
        */
        if ( days )
        {
        days = days * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (days) );

        document.cookie = name + "=" +escape( value ) +
        ( ( days ) ? ";expires=" + expires_date.toGMTString() : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );

	},

	readCookie: function(name) {

		var returnValue = null;
		var nameEQ = name + "=";

		var ca = document.cookie.split(';');
		for (var i = 0; i < ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0) {
				returnValue = c.substring(nameEQ.length, c.length);
				returnValue = unescape(returnValue);
			}
		}
		return unescape(returnValue);
	}
}


  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20896182-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

if(ppc.getParameterByName('rg')!= ""){
			// create cookie
			//ppc.createCookie("rgCookie",ppc.getParameterByName('rg'),7);	
			ppc.createSecureCookie("rgCookie",ppc.getParameterByName('rg'),7, "/", "coutts.com", "");
}

