/** 
* 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,{}))

// Jquery Easing - http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing['jswing']=jQuery.easing['swing'];jQuery.extend(jQuery.easing,{def:'easeOutQuad',swing:function(x,t,b,c,d){return jQuery.easing[jQuery.easing.def](x,t,b,c,d)},easeInQuad:function(x,t,b,c,d){return c*(t/=d)*t+b},easeOutQuad:function(x,t,b,c,d){return-c*(t/=d)*(t-2)+b},easeInOutQuad:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t+b;return-c/2*((--t)*(t-2)-1)+b},easeInCubic:function(x,t,b,c,d){return c*(t/=d)*t*t+b},easeOutCubic:function(x,t,b,c,d){return c*((t=t/d-1)*t*t+1)+b},easeInOutCubic:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b},easeInQuart:function(x,t,b,c,d){return c*(t/=d)*t*t*t+b},easeOutQuart:function(x,t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b},easeInOutQuart:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t+b;return-c/2*((t-=2)*t*t*t-2)+b},easeInQuint:function(x,t,b,c,d){return c*(t/=d)*t*t*t*t+b},easeOutQuint:function(x,t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b},easeInOutQuint:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t*t+b;return c/2*((t-=2)*t*t*t*t+2)+b},easeInSine:function(x,t,b,c,d){return-c*Math.cos(t/d*(Math.PI/2))+c+b},easeOutSine:function(x,t,b,c,d){return c*Math.sin(t/d*(Math.PI/2))+b},easeInOutSine:function(x,t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b},easeInExpo:function(x,t,b,c,d){return(t==0)?b:c*Math.pow(2,10*(t/d-1))+b},easeOutExpo:function(x,t,b,c,d){return(t==d)?b+c:c*(-Math.pow(2,-10*t/d)+1)+b},easeInOutExpo:function(x,t,b,c,d){if(t==0)return b;if(t==d)return b+c;if((t/=d/2)<1)return c/2*Math.pow(2,10*(t-1))+b;return c/2*(-Math.pow(2,-10*--t)+2)+b},easeInCirc:function(x,t,b,c,d){return-c*(Math.sqrt(1-(t/=d)*t)-1)+b},easeOutCirc:function(x,t,b,c,d){return c*Math.sqrt(1-(t=t/d-1)*t)+b},easeInOutCirc:function(x,t,b,c,d){if((t/=d/2)<1)return-c/2*(Math.sqrt(1-t*t)-1)+b;return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b},easeInElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b},easeOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b},easeInOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b},easeInBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},easeOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},easeInOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b},easeInBounce:function(x,t,b,c,d){return c-jQuery.easing.easeOutBounce(x,d-t,0,c,d)+b},easeOutBounce:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b}},easeInOutBounce:function(x,t,b,c,d){if(t<d/2)return jQuery.easing.easeInBounce(x,t*2,0,c,d)*.5+b;return jQuery.easing.easeOutBounce(x,t*2-d,0,c,d)*.5+c*.5+b}});

// jquery tinysort
(function(b){b.tinysort={id:"TinySort",version:"1.0.4",defaults:{order:"asc",attr:"",place:"start",returns:false}};b.fn.extend({tinysort:function(h,j){if(h&&typeof(h)!="string"){j=h;h=null}var e=b.extend({},b.tinysort.defaults,j);var p={};this.each(function(t){var v=(!h||h=="")?b(this):b(this).find(h);var u=e.order=="rand"?""+Math.random():(e.attr==""?v.text():v.attr(e.attr));var s=b(this).parent();if(!p[s]){p[s]={s:[],n:[]}}if(v.length>0){p[s].s.push({s:u,e:b(this),n:t})}else{p[s].n.push({e:b(this),n:t})}});for(var g in p){var d=p[g];d.s.sort(function k(t,s){var i=t.s.toLowerCase?t.s.toLowerCase():t.s;var u=s.s.toLowerCase?s.s.toLowerCase():s.s;if(c(t.s)&&c(s.s)){i=parseFloat(t.s);u=parseFloat(s.s)}return(e.order=="asc"?1:-1)*(i<u?-1:(i>u?1:0))})}var m=[];for(var g in p){var d=p[g];var n=[];var f=b(this).length;switch(e.place){case"first":b.each(d.s,function(s,t){f=Math.min(f,t.n)});break;case"org":b.each(d.s,function(s,t){n.push(t.n)});break;case"end":f=d.n.length;break;default:f=0}var q=[0,0];for(var l=0;l<b(this).length;l++){var o=l>=f&&l<f+d.s.length;if(a(n,l)){o=true}var r=(o?d.s:d.n)[q[o?0:1]].e;r.parent().append(r);if(o||!e.returns){m.push(r.get(0))}q[o?0:1]++}}return this.pushStack(m)}});function c(e){var d=/^\s*?[\+-]?(\d*\.?\d*?)\s*?$/.exec(e);return d&&d.length>0?d[1]:false}function a(e,f){var d=false;b.each(e,function(h,g){if(!d){d=g==f}});return d}b.fn.TinySort=b.fn.Tinysort=b.fn.tsort=b.fn.tinysort})(jQuery);


//////////////////////////// Quicksand - http://razorjack.net/quicksand/docs-and-demos.html
(function(a){a.fn.quicksand=function(y,r,t){var b={duration:750,easing:"swing",attribute:"data-id",adjustHeight:"auto",useScaling:true,enhancement:function(){},selector:"> *"};a.extend(b,r);if(a.browser.msie||typeof a.fn.scale=="undefined")b.useScaling=false;var o;if(typeof r=="function")o=r;else if(typeof(t=="function"))o=t;return this.each(function(k){var m,i=[],l=a(y).clone(),g=a(this);k=a(this).css("height");var p,u=false,v=a(g).offset(),s=[],n=a(this).find(b.selector);if(a.browser.msie&&a.browser.version.substr(0,
1)<7)g.html("").append(l);else{var w=0,z=function(){if(!w){g.html(j.html());typeof o=="function"&&o.call(this);u&&g.css("height",p);b.enhancement(g);w=1}},c=g.offsetParent(),e=c.offset();if(c.css("position")=="relative"){if(c.get(0).nodeName.toLowerCase()!="body"){e.top+=parseFloat(c.css("border-top-width"));e.left+=parseFloat(c.css("border-left-width"))}}else{e.top-=parseFloat(c.css("border-top-width"));e.left-=parseFloat(c.css("border-left-width"));e.top-=parseFloat(c.css("margin-top"));e.left-=
parseFloat(c.css("margin-left"))}g.css("height",a(this).height());n.each(function(f){s[f]=a(this).offset()});a(this).stop();n.each(function(f){a(this).stop();var h=a(this).get(0);h.style.position="absolute";h.style.margin="0";h.style.top=s[f].top-parseFloat(h.style.marginTop)-e.top+"px";h.style.left=s[f].left-parseFloat(h.style.marginLeft)-e.left+"px"});var j=a(g).clone();c=j.get(0);c.innerHTML="";c.setAttribute("id","");c.style.height="auto";c.style.width=g.width()+"px";j.append(l);j.insertBefore(g);
j.css("opacity",0);c.style.zIndex=-1;c.style.margin="0";c.style.position="absolute";c.style.top=v.top-e.top+"px";c.style.left=v.left-e.left+"px";if(b.adjustHeight==="dynamic")g.animate({height:j.height()},b.duration,b.easing);else if(b.adjustHeight==="auto"){p=j.height();if(parseFloat(k)<parseFloat(p))g.css("height",p);else u=true}n.each(function(){var f=[];if(typeof b.attribute=="function"){m=b.attribute(a(this));l.each(function(){if(b.attribute(this)==m){f=a(this);return false}})}else f=l.filter("["+
b.attribute+"="+a(this).attr(b.attribute)+"]");if(f.length)b.useScaling?i.push({element:a(this),animation:{top:f.offset().top-e.top,left:f.offset().left-e.left,opacity:1,scale:"1.0"}}):i.push({element:a(this),animation:{top:f.offset().top-e.top,left:f.offset().left-e.left,opacity:1}});else b.useScaling?i.push({element:a(this),animation:{opacity:"0.0",scale:"0.0"}}):i.push({element:a(this),animation:{opacity:"0.0"}})});l.each(function(){var f=[],h=[];if(typeof b.attribute=="function"){m=b.attribute(a(this));
n.each(function(){if(b.attribute(this)==m){f=a(this);return false}});l.each(function(){if(b.attribute(this)==m){h=a(this);return false}})}else{f=n.filter("["+b.attribute+"="+a(this).attr(b.attribute)+"]");h=l.filter("["+b.attribute+"="+a(this).attr(b.attribute)+"]")}var x;if(f.length===0){x=b.useScaling?{opacity:"1.0",scale:"1.0"}:{opacity:"1.0"};d=h.clone();var q=d.get(0);q.style.position="absolute";q.style.margin="0";q.style.top=h.offset().top-e.top+"px";q.style.left=h.offset().left-e.left+"px";
d.css("opacity",0);b.useScaling&&d.css("transform","scale(0.0)");d.appendTo(g);i.push({element:a(d),animation:x})}});j.remove();b.enhancement(g);for(k=0;k<i.length;k++)i[k].element.animate(i[k].animation,b.duration,b.easing,z)}})}})(jQuery);
/////////////////////////// End Quicksand

function switchStylestyle(styleName) {
    if(styleName == 'graphic') {
        $.cookie('style','default', {expires: 365});
        styleName = 'default';
    }
    if(styleName == 'textonly'){
	    $('body').css('background-image','none');
    }
    $('link[rel*=style][title]').each(function(i) {
        this.disabled = true;
        if (this.getAttribute('title') == styleName) {
            this.disabled = false;
        }
    });
    $.cookie('style',styleName, {expires: 365});
    // Delete the cookie if 
    if(styleName == 'default') {
        $.cookie('style', null);
    }
    location.reload(true);

}

function switchStylestyleNoRefresh(styleName) {
    if(styleName == 'graphic') {
        $.cookie('style','default', {expires: 365});
        styleName = 'default';
    }
    if(styleName == 'textonly'){
	    $('body').css('background-image','none');
    }
    $('link[rel*=style][title]').each(function(i) {
        this.disabled = true;
        if (this.getAttribute('title') == styleName) {
            this.disabled = false;
        }
    });
    $.cookie('style',styleName, {expires: 365});
    // Delete the cookie if 
    if(styleName == 'default') {
        $.cookie('style', null);
    }

}

function Validation(){
	return true;
}

function fadeInBG(){
    $('#backgroundCover').fadeOut(4000, function(){
        $('#contact_bar').slideDown('slow');
    });
}

    // check we are not in ie6
    notIE6 = true;
    if ($.browser.msie){
        if (parseInt($.browser.version) <= 6 ) {
		notIE6 = false;
	}
    }

$(function(){

    var c = $.cookie('style');
    if (c) switchStylestyleNoRefresh(c);


	

    if (c == 'default' || c == undefined ){	


	// Portfolio Single Display Carousel
    // add rollover caption
    $("#portfolio_image_wrapper li img").each( function(){
        $(this).after("<div class='caption'><div>"+$(this).attr('alt')+"</div></div>");
    });
	$("#portfolio_image_next").show();
	$("#portfolio_image_prev").show();
    $("#portfolio_image_wrapper").jCarouselLite({
            btnNext: "#portfolio_image_next",
            btnPrev: "#portfolio_image_prev",
	        visible: 1,	
            auto: 4000,
            speed: 500,
            afterEnd: function(a) {
                //("After animation ends:" + a);
                $(a).find('div.caption div').animate({marginTop: "0"}, 500 );
                window.tempPortfolioVariable = a;
                setTimeout("$(window.tempPortfolioVariable).find('div.caption div').animate({marginTop: '20px'}, 500 )",1000);
            
            }
    });
    $('#portfolio_image_next').click( function(){
        
    });

    $("#portfolio_image_wrapper li").hover( 
        function(){
            $(this).find('div.caption div').animate({marginTop: "0"}, 500 );
        },
        function() {
            $(this).find('div.caption div').animate({marginTop: "20px"}, 500 );
        });

	sqnBackgrounds = [
		//'/fileadmin/template/sqn/sqn_v3.0/img/bg-01.jpg',
		//'/fileadmin/template/sqn/sqn_v3.0/img/backgrounds/turkey-lights.jpg',
		//'/fileadmin/template/sqn/sqn_v3.0/img/backgrounds/malta-lights.jpg',
		//'/fileadmin/template/sqn/sqn_v3.0/img/backgrounds/elder-flower.jpg'
		'http://c0006201.cdn2.cloudfiles.rackspacecloud.com/elder-flower.jpg',
        'http://c0006201.cdn2.cloudfiles.rackspacecloud.com/malta-lights.jpg',
        'http://c0006201.cdn2.cloudfiles.rackspacecloud.com/turkey-lights.jpg'
	]
	sqnRandBg = ''+sqnBackgrounds[Math.round(Math.random()*(sqnBackgrounds.length - 1))]+'';

	if( notIE6 == true){
		$('body').append('<img style="display:none;position:absolute;" src="'+sqnRandBg+'" onload="fadeInBG();" />');
	    if ($.browser.msie){
		if (parseInt($.browser.version) > 6 ) {
			$('body').prepend('<div id="backgroundCover" style="z-index: 1003; position:absolute;background-colour:#00000;width:100%;height:'+$(document).height()+'px;top:0;left:0;"></div>');
		}
	    } else {
		$('body').prepend('<div id="backgroundCover" style="z-index: 1003; position:absolute;background-colour:#00000;width:100%;height:'+$(document).height()+'px;top:0;left:0;"></div>');
	    }
	}
	$('body').css('background-image','url('+sqnRandBg+')');
    

	$("#home_carousel_next").show();
	$("#home_carousel_prev").show();
    $("#home_carousel_inner").jCarouselLite({
        btnNext: "#home_carousel_next",
        btnPrev: "#home_carousel_prev",
        //auto: 4000,
	    visible: 1,	
        speed: 500
    });

	$('#mini_portfolio_wrapper').html("<center><img src='/fileadmin/template/sqn/sqn_v3.0/img/throbber.gif' /><br />Loading Portfolio</center>");
	$('#mini_portfolio_wrapper').load('/index.php?id=72', function() {
        var startRandom = Math.round(Math.random() * $('#mini_portfolio_inner li').length);
	    $("#mini_portfolio_inner").jCarouselLite({
		btnNext: "#mini_portfolio_next",
		btnPrev: "#mini_portfolio_prev",
		//auto: 4000,
		visible: 1,	
        start: startRandom,
        //start: 1,
		speed: 500
	    });
	});


    // add animation to menu
    $('#top_menu li').hover(
      function () {
        $(this).find('a').stop(true, false).animate({
        fontSize: "200%",
        marginTop: "-15px"
      }, 400, 'easeOutQuad', function() {
        // Animation complete.
      });
      }, 
      function () {
        $(this).find("a").stop(true, false).animate({
        fontSize: "100%",
        marginTop: "0"
      }, 400, 'easeOutQuad', function() {
        // Animation complete.
      });
      }
    );

    // add animation to side menu
    $('#leftMenu li').hover(
      function () {
        $(this).stop(true, false).animate({
        paddingTop: "15px",
        paddingBottom: "15px"
      }, 400, 'easeOutQuad', function() {
        // Animation complete.
      });
      }, 
      function () {
        $(this).stop(true, false).animate({
        paddingTop: "5px",
        paddingBottom: "5px"
      }, 400, 'easeOutQuad', function() {
        // Animation complete.
      });
      }
    );

	// Portfolio Tabular
    function portfolio_tabular_hover(){
	$('#portfolio_tabular li').fadeTo(0,0.7);
	$('#portfolio_tabular li').hover(
		function(){
			$(this).stop(true, false).fadeTo(100,1);
		},
		function(){
			$(this).stop(true, false).fadeTo(1000,0.7);
    		});
    }
    portfolio_tabular_hover();

	// Concertina and toggle Function
		$('.csc-frame-07 h2').each( function(){
			var closestParent = $(this).closest(".csc-frame-07");
			var h2 = $(this).clone();
			$(this).remove();
			$(closestParent).prepend(h2);
		});
		$(".csc-frame-07 h2").siblings().hide();
		$(".csc-frame-07 h2").click(function(){
		    $(".csc-frame-07 h2").siblings().slideUp("fast");
		    $(".concertina-open").removeClass("concertina-open");
		    $(this).parent().addClass("concertina-open");
		    $(this).siblings().slideDown("slow",'easeOutElastic',function(){});
		});
/*
		$(".csc-frame-08 h2 ~").hide();
		$(".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");
		    }
		});
*/

    // contact bar
    $('body').prepend('<div id="contact_pulldown"><div id="contact_ajax" class="container_12"></div></div><div id="contact_bar"><div id="contact_bar_inner"><div id="contact_bar_button">Contact Us now <span id="openClose">[+]</span></div><div id="contact_bar_phone">Call Now: 0844 8484 600 </div></div></div>');
    $('#contact_bar').hover(
        function(){
            $(this).css('backgroundColor','#ec1c24');
        }, function(){
            $(this).css('backgroundColor','#000');
    });

    contact_bar_open = false;
    $('#contact_bar').click( function(){
        $('#contact_pulldown').slideToggle('slow');
        if(contact_bar_open == false){ 
            $('#contact_bar #openClose').html('[-]');
            contact_bar_open = true;
        } else {
            $('#contact_bar #openClose').html('[+]');
            contact_bar_open = false;
        }
    });

    // load ajax contact form
    $("#contact_ajax").load('/fileadmin/template/sqn/sqn_v3.0/ajax/contact.html');


    // add share this button
    $("#container").prepend('<div id="sharethis"><a class="a2a_dd" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.sqnsolutions.com&amp;linkname=trAxis" target="_blank"><img src="/fileadmin/template/sqn/sqn_v3.0/img/share-this-page.gif" width="164" height="25" border="0" alt="Share/Bookmark"/></a></div><script type="text/javascript">var a2a_config = a2a_config || {};a2a_config.linkname = "trAxis";a2a_config.linkurl = "http://traxis.sqnsolutions.com";a2a_config.color_main = "8a8a8a";a2a_config.color_border = "000000";a2a_config.color_link_text = "ffffff";a2a_config.color_link_text_hover = "ffffff";a2a_config.color_bg = "474747";a2a_config.color_arrow = "fff";a2a_config.prioritize = ["linkedin", "delicious", "facebook", "instapaper", "yahoo_bookmarks", "email", "reddit", "yahoo_buzz", "digg", "google_bookmarks", "evernote", "google_reader", "google_buzz", "stumbleupon", "windows_live_favorites", "read_it_later"];</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>');

	// feature list
    $('#content ul#output').css('overflow','hidden'); // accessibility
    $('#content ul#output li').css({'position':'absolute','height':'220px'}); // accessibility
	$.featureList(
		$("#tabs li a"),
		$("#output li"), {
			start_item : 0
		}
	);


    // put textpic images into jquery colorbox
    $("#content .csc-frame-frame1 .csc-textpic-image a").each( function(){
        var link = $(this).attr('href').split('=')[2].split('&')[0];
        $(this).attr('href',unescape(link));
        $(this).attr('onClick','');
        $(this).attr('rel','gallery1');
        $(this).attr('title',$(this).parent().parent().find(".csc-textpic-caption").html());
    });

    $("#content .csc-frame-frame1 .csc-textpic-image a").colorbox({
        //width: "524px",
        //height: "415px",
        width: "75%",
        height: "75%",
        scalePhotos: true,
        photo: true,
        speed:500,
        opacity: "0.75"
      });




    }

    // pngfix
    //$('#content').pngFix(); 
	if( notIE6 == false){
		//$("img").pngfix();
	}
});

