/** 
* Jquery cookie plugin 
**/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('j.5=u(9,a,2){6(h a!=\'v\'){2=2||{};6(a===m){a=\'\';2.3=-1}4 3=\'\';6(2.3&&(h 2.3==\'n\'||2.3.k)){4 7;6(h 2.3==\'n\'){7=w C();7.B(7.z()+(2.3*A*o*o*E))}l{7=2.3}3=\'; 3=\'+7.k()}4 8=2.8?\'; 8=\'+2.8:\'\';4 b=2.b?\'; b=\'+2.b:\'\';4 c=2.c?\'; c\':\'\';d.5=[9,\'=\',q(a),3,8,b,c].t(\'\')}l{4 g=m;6(d.5&&d.5!=\'\'){4 e=d.5.x(\';\');D(4 i=0;i<e.f;i++){4 5=j.r(e[i]);6(5.p(0,9.f+1)==(9+\'=\')){g=y(5.p(9.f+1));s}}}F g}};',42,42,'||options|expires|var|cookie|if|date|path|name|value|domain|secure|document|cookies|length|cookieValue|typeof||jQuery|toUTCString|else|null|number|60|substring|encodeURIComponent|trim|break|join|function|undefined|new|split|decodeURIComponent|getTime|24|setTime|Date|for|1000|return'.split('|'),0,{}))

/**
* Styleswitch stylesheet switcher built on jQuery
**/
$(document).ready(function() {
	var c = $.cookie('style');
	if (c) switchStylestyle(c);
});

function switchStylestyle(styleName) {
	$('link[@rel*=style][@title]').each(function(i) {
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	$.cookie('style',styleName, {expires: 365});
}

// header images - define array of images here and wone will be selected randomly and inserted into header with a nice fade
headerImages =  
[ 
 "/fileadmin/template/main/ukcg/img/test-header.jpg",
 "/fileadmin/template/main/ukcg/img/header-02.jpg",
 "/fileadmin/template/main/ukcg/img/header-03.jpg"
]
var selectedImage = headerImages[Math.floor(Math.random()*headerImages .length)];

// Initialise Things
jQuery(function(){

	// it sub group popup link
	$("a[href='index.php?id=12390']").click(function() {
		//window.open('index.php?id=12390','height=630,width=950');
		window.open ("/index.php?id=12390","mywindow","resizable=1,width=950,height=630"); 
		//if (window.focus) {newwindow.focus()}
		return false;
	});
	
	if ($.cookie('style') != "textonly") {
		// initialise things if not text-only
               $("#header-image-wrapper").hide().html('<img id="jheaderImage" src="'+selectedImage+'" width="848" height="139" />');
               $('#jheaderImage').load(function () {
                    $("#header-image-wrapper").fadeIn(2000);
               });
	}
});

// Concertina Function
$(document).ready(function(){

			$(".csc-frame-07").each(function(){
				$(this).wrapInner("<div class='csc-frame-07-inner'></div>");
				cscHeader07 = $("h2", this).clone().get(0);
				$("h2", this).remove();
				$(this).prepend(cscHeader07);
			});
			$(".csc-frame-07-inner").hide();
			$(".csc-frame-07 h2").click(function(){
			    $(".csc-frame-07-inner").slideUp("slow");
			    $(".concertina-open").removeClass("concertina-open");
			    $(this).parent().addClass("concertina-open");
			    $(this).siblings().slideDown("slow",function(){});
			});


			$(".csc-frame-08").each(function(){
				$(this).wrapInner("<div class='csc-frame-08-inner'></div>");
				cscHeader08 = $("h2", this).clone().get(0);
				$("h2", this).remove();
				$(this).prepend(cscHeader08);
			});
			$(".csc-frame-08-inner").hide();
			$(".csc-frame-08 h2").click(function(){
			    $(this).siblings().slideToggle("normal");
			    if( $(this).parent().hasClass("toggle-open") ){
				$(this).parent().removeClass("toggle-open");
			    } else {
				$(this).parent().addClass("toggle-open");
			    }	
			});

			//$(".csc-frame-08 h2 ~").hide();
			//$(".csc-frame-08").wrapInner("<div class='csc-frame-08-inner'></div>");
			//$(".csc-frame-08 h2").clone().prepend(this.parent().parent());
			//$(".csc-frame-08 h2").click(function(){
			//    $(this).siblings().slideToggle("fast");
			//    if( $(this).parent().hasClass("toggle-open") ){
			//	$(this).parent().removeClass("toggle-open");
			//    } else {
			//	$(this).parent().addClass("toggle-open");
			//    }
			//});

			// check url vars and perform actions
			window.urlvars = getUrlVars();
			if ( window.urlvars.view == "single_post" ) {
				$('.csc-frame-08-inner').show();
				$('.csc-frame-08 h2').click(function(){});
			}

			// forum - show edit form on prebiew page
			if( $('.tx-chcforum-pi1-forumTextBig').html() == "This is a preview of your message." ) {
				$('.csc-frame-08-inner').show();
			}

});

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars(){
      var vars = [], hash;
      var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

      for(var i = 0; i < hashes.length; i++)
      {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
      }

      return vars;
}


function bookmarkSite() {
	if ($.browser.msie) {
		window.external.AddFavorite("http://www.ukcg.org.uk', 'UKCG - United Kingdom Construction Group");
	}

	else {
		alert("Sorry the bookmark function only works with Internet Explorer");
	}
        return false;
}

