var domain = (document.domain == "localhost" || document.domain == "192.168.140.50") ? "localhost:8080/cyber-duck.co.uk/2010" : document.domain;
var eventStr;
var last_clicked;
var staySame;
var frameID = -1;
var fromFlash = 0;
 if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
 {
  document.styleSheets[0].addRule('.transparent', 'behavior: url(js/iepngfix.htc)');
 }

$(document).ready(function(){
    var flashvars = {};
    var params = {};
    var attributes = {};
     
    flashid = $('.top-banner').attr('id');
    
    if (noFlash==false){
        params.wmode = "transparent";
        flashvars.section = 0;
        flashvars.sectionspath = "sections";
        flashvars.debug = 0;
        swfobject.embedSWF("main.swf", flashid, "960", "365", "9", "media/expressInstall.swf", flashvars, params, attributes);
    }
    iniSubService();
    iniAjaxlink();
    iniServiceLink();
    iniNewslink();
    imageSlide();
    imageCarousel();
    initAccortion();
    iniFancybox();
    $.address.change(function(event) {
        if((event.pathNames=='')|| (typeof(event.parameters.update) == 'undefined'))
        {
            return false;
        }
        // do something depending on the event.value property, e.g.

        
        eventStr = event.path;
        
        if ( $('#'+event.parameters.update).length==0)
        {
			
            // load news main page
            if(event.parameters.update=='news-content')
            {
                eventPath ='/blog.php' ;
            }
            else if(event.parameters.update=='company-content')
            {
                eventPath ='/about-us.php' ;
            }
            else if(event.parameters.update=='job-content')
            {
                eventPath ='/digital-agency-jobs.php' ;

            }
            else
            {
                eventPath = '/web-solutions.php';
            }

            $('#content').load('_jx_getPages.php?page='+eventPath+'&update=content', function()
            {
                if(event.parameters.update=='service-sub-content' || event.parameters.update=='service-content')
                {
                    pathVars = getPath(event.path);
                    //if(event.parameters.update=='service-content') setMotion($('#'+pathVars[1]), 'services');

                    $('#service-content').load('_jx_getPages.php?page='+pathVars[0]+'&update=service-content', function() {
                        
                        setMotion($('#'+pathVars[1]), 'services','not log');
                        iniAjaxlink(pathVars[0]);
                        iniSubService(pathVars[0]);
                        initAccortion();
                        iniFancybox();
                        iniSifr();
                        if(event.parameters.update=='service-sub-content')
                        {
							if(fromFlash==1){
								fromFlash=0;
								goToFrame(event.path);
							}
							loadingPage(event);
                        }
                    });
                }
                else if(event.parameters.update=='company-content')
                {
                    pathVars = getPath(event.path);
                    $('#company-content').load('_jx_getPages.php?page='+event.path+'&update=company-content', function() {
                        setMotion($('#'+pathVars[1]), 'company','not log');
                        initAccortion()
                        iniSifr();
                        iniFancybox();
                        goToFrame(event.path);
                        
                    });
                }
                else if(event.parameters.update=='job-content')
                {
                    
                    //$('#job-content').load('_jx_getPages.php?page='+event.path+'&update=job-content', function() {
                        initAccortion()
                        iniSifr();
                        iniFancybox();
                        iniAjaxlink(event.path);
                        iniSubService();
                        goToFrame(event.path);                        

                        iniServiceLink();
                        iniSubService(eventPath);
        
                }
                else
                {   
					initAccortion();
                    iniSifr();
                    iniFancybox();					
                    loadingPage(event);
                }
            });

        }
        else
        {
            //alert(event.parameters.stayframe);			
            loadingPage(event);
        }
        return true;
     });

    $('#footer-tabs').tabs();

});


function update_slidingmenu()
{
   
    mylocation = window.location.href;

    
    
    if( mylocation.indexOf('web-technology-company.php') != -1 && last_clicked.indexOf('web-technology-company.php') == -1)
    {
        
        $('#scrollcontainer .serv-webtechno:last').trigger('click');
    }

    
    
    if( mylocation.indexOf('web-solutions-design.php') != -1 && last_clicked.indexOf('web-solutions-design.php') == -1 )
    {
        $('#scrollcontainer .serv-webproduct:last').trigger('click');
    }

    if( mylocation.indexOf('online-brand.php') != -1 && last_clicked.indexOf('online-brand.php') == -1)
    {
        $('#scrollcontainer .serv-branding:last').trigger('click');
    }

    if( mylocation.indexOf('search-engine-marketing-company.php') != -1 && last_clicked.indexOf('search-engine-marketing-company.php') == -1)
    {
        $('#scrollcontainer .serv-marketing:last').trigger('click');
    }

   if( mylocation.indexOf('digital-consultancy.php') != -1 && last_clicked.indexOf('digital-consultancy.php') == -1 )
    {
        $('#scrollcontainer .serv-consultacy:last').trigger('click');
    }

     if( mylocation.indexOf('company-team.php') != -1 && last_clicked.indexOf('company-team.php') == -1 )
    {
        $('#scrollcontainer .cs-team:last').trigger('click');
    }

    if( mylocation.indexOf('technology-partners.php') != -1 && last_clicked.indexOf('technology-partners.php') == -1 )
    {
        $('#scrollcontainer .cs-partners:last').trigger('click');
    }

     if( mylocation.indexOf('corporate-social-responsability.php') != -1 && last_clicked.indexOf('corporate-social-responsability.php') == -1 )
    {
        $('#scrollcontainer .cs-csr:last').trigger('click');
    }

    
}


function loadingPage(event)
{
	updatePageId = event.parameters.update;
	eventPath = event.path;
	if (event.parameters.s) {		
		eventPath = event.path + '&s=' +event.parameters.s;				
	}
    goToFrame(eventPath);	
    $('#'+updatePageId).load('_jx_getPages.php?page='+eventPath+'&update='+updatePageId, function() {
		
        iniAjaxlink(eventPath);
        iniNewslink(eventPath);
        imageSlide();
        imageCarousel();
        iniServiceLink();
        iniSubService(eventPath);
        initAccortion()
        iniSifr();
        iniFancybox();
		
        // SYLV: trigger the flash
        // alert('sylv debug: changing flash: '+ eventPath);        
        //pathVars = getPath(eventPath);
                
        update_slidingmenu();
        //iniMotion(eventPath); to do       
        if(eventPath=='/web-contact.php') loadMap();
		if(event.parameters.openComment.length){ // open the comment accordion on post page
			
			$('.accordion-area').accordion( "activate" ,parseInt(event.parameters.openComment));
			window.scrollTo(0, $('#respond').position().top);
		}
        
    });
}

function iniAjaxlink(pathName)
{
    
    $('.ajaxlink').each(function(){ // ajax
        if(pathName && $(this).attr('href').match(pathName.substring(1)))
        {
            //$(this).addClass('current');
        }
        $(this).click(function(e){
            //$('.ajaxlink').removeClass('current');
            //$(this).addClass('current');
            e.preventDefault();            
            $.address.title($(this).attr('title'));
            
            if ($(this).attr('href').match('digital-agency-jobs')){
                $('#content').removeClass();
                $('#content').addClass('active-job-overview-nav');
                $.address.value($(this).attr('href')+'?update=job-content');
            }
            else $.address.value($(this).attr('href')+'?update=content');
        });
    });

}


function changeAddress(path){
    //$.address.title($(this).attr('title'));    
    if (path.match('digital-agency-jobs.php')){
        $('#content').removeClass();
        $('#content').addClass('active-job-overview-nav');
        $.address.value(path+'?update=job-content');
    }else if(path.match('web-solutions-design')||path.match('online-brand')||path.match('search-engine-marketing-company')||path.match('digital-consultancy')||path.match('web-technology-company')	){
        $.address.value(path+'.php?update=service-sub-content');
    }else if(path.match('tablet-app-design') || path.match('eye-tracking.php')){
		fromFlash = 1;
        $.address.value(path+'?update=service-sub-content');
    }else if(path.match('marketing-case-study-sparks-direct') || path.match('user-centred-design-solution-for-betting-giant') || path.match('officecavalry-com-launches-with-a-bang')){
        $.address.value('blog/index.php/'+path+'?update=news-content');
    }else{
        $.address.value(path+'?update=company-content');
    }
}
function changeAddress2(path){
    if (path.match('digital-agency-jobs.php')){
        $('#content').removeClass();
        $('#content').addClass('active-job-overview-nav');
        $.address.value(path+'?update=job-content');
    }else{
        staySame = 1;
        $.address.value(path+'?update=content');
    }

}


function iniServiceLink()
{
    //$('.servicelink').each(function(){
        $('.servicelink').click(function(e){
                //$('#mn-services a').addClass('current');
                e.preventDefault();
                $.address.title($(this).attr('title'));
                $.address.value($(this).attr('href')+'?update=service-sub-content');
        });
    //});

}


function iniNewslink(pathName)
{
    $('#ns-form').submit(function(e){
         e.preventDefault();          
         $('#news-content').load('blog/index2.php', {'s':$('#s').val()} ,function() {            
            iniSifr();
            iniNewslink(pathName);
         });
    });
    
    $('#commentform').submit(function(e){ // comments form
         e.preventDefault();
         $('.msgballoon').remove();
         if($('#author').val()=='' ){
             $('#author').after('<div class="err-ico msgballoon"></div>');
             return;
         }else{
             $('#author').after('<div class="ok-ico msgballoon"></div>');
         }
         if($('#email').val()=='' ){
             $('#email').after('<div class="err-ico msgballoon"></div>');
             return;
         }else{
             $('#email').after('<div class="ok-ico msgballoon"></div>');
         }
         if($('#comment').val()=='' ){
             $('#comment').after('<div class="err-ico msgballoon"></div>');
             return;
         }else{
             $('#comment').after('<div class="ok-ico msgballoon"></div>');
         }
         $.post("blog/wp-comments-post-ajax.php", $("#commentform").serialize(),
            function(data) {
                if(data.length==1){
                    switch(data){
                        case '0': errorMsg = 'Sorry, comments are closed for this item.'; break;
                        case '1': errorMsg = 'Sorry, you must be logged in to post a comment.'; break;
                        case '2': errorMsg = 'Error: please fill the required fields (name, email)'; break;
                        case '3': errorMsg = 'Error: please enter a valid email address.'; break;
                        case '4': errorMsg = 'Error: please type a comment.'; break;
                    }
                    $('#result').html(errorMsg);
                }else{
                    $('#news-content').html(data);
                    iniSifr();
                    iniNewslink(pathName);
                }
        });
    });

    $('#news-content a:not(.noajax),.news-link a, a.bloglink').each(function(e){ // ajax
        if($(this).attr('target')=='_blank'){
            return true;
        }
        if($(this).parents(".news-link").length){            
            if(pathName && $(this).attr('href').indexOf(pathName.substring(1))>-1 ){
                $('.news-link a').removeClass('or-active');
                $(this).addClass('or-active');
            }
        }
        $(this).click(function(e){
            e.preventDefault();
            $(this).addClass('or-active');
            $.address.title($(this).attr('title'));
			if($(this).hasClass('comment-link'))
			{
				$.address.value($(this).attr('href')+'?update=news-content&openComment='+$(this).attr('rel'));
			}
			else if($(this).hasClass('search-link'))
			{
				$.address.value($(this).attr('href')+'&update=news-content');
			}
			else
			{
				$.address.value($(this).attr('href')+'?update=news-content');
			}	
        });
    });
    
}

function iniFancybox()
{

    $("a.fancybox").fancybox({
        'type'          :   'iframe',
        'showCloseButton'	: false,
		'speedIn'		:	600,
		'speedOut'		:	200,
        'width'         :   507 ,
        'height'        :   548,
        'padding'       :   0,
        'titleShow'     :   false,
        'centerOnScroll':   false,
        'scrolling'     :   'no',
        'autoScale'         :   false
	});
    
   $("a.applyfancy").fancybox({
        'type'          :   'iframe',
        'showCloseButton'	: false,
		'speedIn'		:	600,
		'speedOut'		:	200,
        'width'         :   507 ,
        'height'        :   536,
        'padding'       :   0,
        'titleShow'     :   false,
        'centerOnScroll':   false,
        'scrolling'     :   'no',
        'autoScale'         :   false
	});
        
     $("a.hostingfancy").fancybox({
        'type'          :   'iframe',
        'showCloseButton'	: false,
		'speedIn'		:	600,
		'speedOut'		:	200,
        'width'         :   507 ,
        'height'        :   508,
        'padding'       :   0,
        'titleShow'     :   false,
        'centerOnScroll':   false,
        'scrolling'     :   'no',
        'autoScale'         :   false
	});
	
    $("a.flashfancy").fancybox({
        'type'          :   'iframe',
        'showCloseButton'	: true,
		'speedIn'		:	600,
		'speedOut'		:	200,
        'width'         :   400 ,
        'height'        :   265,
        'padding'       :   20,
        'titleShow'     :   false,
        'centerOnScroll':   false,
        'scrolling'     :   'no',
        'autoScale'         :   false
	});

        
}

function iniShowcase(){
    
    $('.cat-showcase select').change(function(){
        $('#showcase-area').fadeOut('slow');
        $('#showcase-area').load('_ajax_showcase.php?cat='+$('.cat-showcase select').val(), function() {
            initPage();
        });
        $('#showcase-area').fadeIn('slow');
    });

}

function initPage(){
    iniTesti();
    initTip();
    $('.paginator a').click(function(){
        pageTracker._trackPageview('/showcase-'+$('.cat-showcase select').val()+'-'+$(this).attr('title'));
        $('#showcase-area').fadeOut('slow');
        $('#showcase-area').load('_ajax_showcase.php?cat='+$('.cat-showcase select').val()+'&page='+$(this).attr('title'), function() {
            initPage();
        });
        $('#showcase-area').fadeIn('slow');
     });
}
    
function iniTesti(){
    $('.ico-test').click(function(e){
        $(this).parents('.shproject-area').children('.shproject-thmb').children('.sh-img').fadeOut('slow');
        $(this).parents('.shproject-area').children('.shproject-thmb').children('.testi-block').fadeIn('slow');

    });
    $('.back-to-show').click(function(e){
        $(this).parents('.shproject-thmb').children('.testi-block').fadeOut('slow');
        $(this).parents('.shproject-thmb').children('.sh-img').fadeIn('slow');
    });
}

function iniAward()
{
    $('.award-img img').each(function(){
        backgroundimg = $(this).attr('src');
       $(this).parents('.award-img').css('background-image','url('+backgroundimg+')');
       $(this).remove();

    });

    $('.award-year-nav a').click(function(){
        $('.award-year-nav a').removeClass('or-active');
        $(this).addClass('or-active');
        $('.awards-all').fadeOut('slow');
        $('.awards-'+$(this).attr('rel')).fadeIn('slow');
    });
    
}

function iniSubService(pathName)
{
    $('.service-subpage-navig a').each(function(){ // ajax
        if(pathName && $(this).attr('href').indexOf(pathName.substring(1))>-1 ){
            $('#service-content').removeClass();
            $('#service-content').addClass('active-'+$(this).attr('id'));
        }
        $(this).click(function(e){
            e.preventDefault();
            $('#service-content').removeClass();
            $('#service-content').addClass('active-'+$(this).attr('id'));
            $.address.title($(this).attr('title'));
            $.address.value($(this).attr('href')+'?update=service-sub-content');
        });
    });

    $('.company-subpage-navig a').each(function(){ // ajax
        if(pathName && $(this).attr('href').indexOf(pathName.substring(1))>-1 ){
            $('#company-content').removeClass();
            $('#company-content').addClass('active-'+$(this).attr('id'));
        }
        $(this).click(function(e){
            e.preventDefault();
            $('#company-content').removeClass();
            $('#company-content').addClass('active-'+$(this).attr('id'));
            $.address.title($(this).attr('title'));
            $.address.value($(this).attr('href')+'?update=company-sub-content');
            
        });
    });
    $('.team-nav a').click(function(e){
        e.preventDefault();
        $.address.title($(this).attr('title'));
        if($(this).hasClass('job-link'))
            $.address.value($(this).attr('href')+'?update=job-content');
        else
            $.address.value($(this).attr('href')+'?update=company-content');
        
        
    });


    $('.job-subpage-navig a').each(function(){ // ajax
        
        $(this).click(function(e){
            e.preventDefault();
            $('#content').removeClass();
            $('#content').addClass('active-'+$(this).attr('id'));
            $.address.title($(this).attr('title'));
            $.address.value($(this).attr('href')+'?update=job-content');
        });
    });


}

function initAccortion(){
    if( $('.accordion-area').length){
        /*
        $('.accordion-area .acchead').click(function() {
            $(this).next().toggle('fast');
            $(this).toggleClass('opened');
            iniSifr();
            return false;
        }).next().hide();
        */       
            $('.accordion-area').accordion(
            {
                active: false,
                header: '.acchead',
                navigation: false,
                event: 'click',
                fillSpace: false,
                animated: 'easeslide',
                collapsible: true,
                autoHeight:false,
                alwaysOpen: false

            });
    }

}

function openComment(index)
{
	$('.accordion-area').accordion( "activate" ,index);
	window.scrollTo(0, $('#respond').position().top);
	//location.href="#respond";
}

function setMotion(obj, pagecategory,logAddress) // services scroll menu
{ 
    var backpos = "";
    var split_array = '';
    last_clicked = $(obj).attr('href');
    
    logAddress = logAddress || 'log';
    
    if (pagecategory == "services")
    {
        $(".menubar").scrollTo("#"+ $(obj).attr('id'), 700, {'axis':'x'});

        backpos = $(obj).css('background-position');
        if(typeof(backpos) == 'undefined') { backpos = $(obj).css('background-position-x') + ' ' + $(obj).css('background-position-y') };

        split_array = backpos.split(' ', 2);
        backx = split_array[0];
        $(obj).css('background-position', backx+' -24px');

        $('#services-subnav').css('background','url(images/arrow-subnav-bgrnd.gif) no-repeat')

        $('#filler a').each(function (){
            $(this).attr('id', 'id' + Math.floor(Math.random()* 100000) );
        });

        $('#scrollcontainer').append($('#filler').html());
        $('#scrollcontainer').width( $('#scrollcontainer').width()+ 1000  );

        $('#filler a').each(function (){
               $(this).attr('id', 'null');
        });

        if(logAddress=='log') {
            $.address.title($(obj).attr('title'));
            $.address.value($(obj).attr('href')+'?update=service-content');
        }

        $('#service-content').removeClass();
        if($(obj).hasClass('serv-webproduct')) $('#service-content').addClass('active-web-prod-overview-nav');
        else if($(obj).hasClass('serv-branding')) $('#service-content').addClass('active-br-overview-nav');
        else if($(obj).hasClass('serv-marketing')) $('#service-content').addClass('active-om-overview-nav');
        else if($(obj).hasClass('serv-consultacy')) $('#service-content').addClass('active-con-overview-nav');
        else if($(obj).hasClass('serv-webtechno')) $('#service-content').addClass('active-web-tech-overview-nav');

    }
    else if (pagecategory == "company")
    {
        
        $('.menu-text').removeClass('color-text');
        $(obj).addClass('color-text');


        $(".menubar").scrollTo("#"+ $(obj).attr('id'), 700, {'axis':'x'});

        backpos = $(obj).css('background-position');
        if(typeof(backpos) == 'undefined') { backpos = $(obj).css('background-position-x') + ' ' + $(obj).css('background-position-y') };
        
        split_array = backpos.split(' ', 2);

        backx = split_array[0];

        $(obj).css('background-position', backx+' -15px');

        $('#company-subnav').css('background','url(images/arrow-subnav-bgrnd.gif) no-repeat')



        $('#filler a').each(function (){
            $(this).attr('id', 'id' + Math.floor(Math.random()* 100000) );
        });

        $('#scrollcontainer').append($('#filler').html());
        $('#scrollcontainer').width( $('#scrollcontainer').width()+ 800  );

         $('#filler a').each(function (){
           $(this).attr('id', 'null');
        });

        if(logAddress=='log') {
            staySame = 1;
            $.address.title($(obj).attr('title'));
            $.address.value($(obj).attr('href')+'?update=company-content');
        }

    }
 
    
}

function getPath(sPath)
{
    
    var menuid;
    var pagecategory='services';
    if(sPath.match('web-solutions-design.php') || sPath.match('user-centred-design.php') || sPath.match('top-web-design-company.php') || sPath.match('web-programming.php') || sPath.match('flash-applications-development.php') || sPath.match('cms-for-websites.php') || sPath.match('mobile-app-design.php') || sPath.match('tablet-app-design.php'))
    {        
        eventPath = '/web-solutions-design.php';
        menuid = 'menu1';
    }
    else if(sPath.match('online-brand.php') ||sPath.match('web-logo-design.php') ||sPath.match('web-copywriting.php') ||sPath.match('website-animation.php'))
    {

        eventPath = '/online-brand.php';
        menuid = 'menu2';
    }
    else if(sPath.match('search-engine-marketing-company.php') || sPath.match('organic-search-engine-marketing.php') || sPath.match('website-speed-optimisation.php') || sPath.match('search-engine-advertising.php') ||sPath.match('google-analytics-implementation.php') ||sPath.match('multivariate-testing.php')||sPath.match('email-marketing-management.php') ||sPath.match('online-viral-marketing.php') ||sPath.match('online-publicity.php') ||sPath.match('corporate-e-cards.php') ||sPath.match('user-experience-optimisation.php') )
    {

        eventPath = '/search-engine-marketing-company.php';
        menuid = 'menu3';
    }
    else if(sPath.match('digital-consultancy.php') || sPath.match('web-market-research.php') || sPath.match('website-analytics.php') ||sPath.match('stakeholder-consultation.php') ||sPath.match('qualitative-focus-groups.php') ||sPath.match('eye-tracking.php') ||sPath.match('testing-usability.php') ||sPath.match('website-surveys.php')||sPath.match('competitor-research.php'))
    {

        eventPath = '/digital-consultancy.php';
        menuid = 'menu4';
    }
    else if(sPath.match('web-technology-company.php') ||sPath.match('web-2.0-website-design.php') ||sPath.match('secure-web-hosting.php') || sPath.match('e-commerce-solutions-uk.php') ||sPath.match('touch-screen-website.php') ||sPath.match('software-as-a-service.php') ||sPath.match('social-media-development'))
    {

        eventPath = '/web-technology-company';
        menuid = 'menu5';
    }
    else if(sPath.match('company-team.php'))
    {

        eventPath = '/company-team.php';
        menuid = 'menu1';
        pagecategory = 'company';
    }
    else if(sPath.match('technology-partners.php'))
    {

        eventPath = '/technology-partners.php';
        menuid = 'menu2';
        pagecategory = 'company';
    }
    else if(sPath.match('corporate-social-responsability.php'))
    {

        eventPath = '/corporate-social-responsability.php';
        menuid = 'menu3';
        pagecategory = 'company';
    }
    else
    {
        eventPath = '0';
        menuid = '0';
        
    }

    returns = new Array(eventPath,menuid, pagecategory);
    return returns;

}

function iniMotion(sPath1)
{
     arr1 = getPath(sPath1);
     if (arr1[0]!=0) setMotion(arr1[1], arr1[2],'not log');
}

function loadMap()
{
    
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("gmap"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(51.644607,-0.298299), 15);
        var point = new GLatLng(51.644607,-0.298299);
        var marker = new GMarker(point);
        map.addOverlay(marker);

        GEvent.addListener(marker, "click", function()
        {marker.openInfoWindowHtml("Marker #<b>" + number + "</b>"); });
    }
    
}

// JavaScript Document
function setFlashMovieFrameId(frameID)
{

	var retVal = false;

	// Get the flash element
	var flashElement = document.getElementById('home-flash');
	if (flashElement)
	{
        if(typeof(flashElement.SetVariable)!='undefined')
        {
            //alert("Sending: "+frameID);
            flashElement.SetVariable("section", frameID);
            retVal = true;
        }
	}

	return retVal;
}

function setFlashMovieFrameIdStaff(frameID)
{
	var retVal = false;

	// Get the flash element
	var flashElement2 = document.getElementById('home-flash');
	if (flashElement2)
	{
        if(typeof(flashElement2.SetVariable)!='undefined')
        {
            //alert("Sending staff:"+frameID);
            flashElement2.SetVariable("staff", frameID);
            retVal = true;
        }
	}

	return retVal;
}

function flashTracking(flashname)
{
	pageTracker._trackPageview(flashname);
}

function goToFrame(frameName)
{
    //load default banners
    load_banners();
    
    staffId =-1;
    strCut = 'http://'+domain;
    $('.ajaxlink').removeClass('current');
    if (frameName.match(strCut)){ // remove http://domain from url
        frameName = frameName.substr(strCut.length+1);        
    }
    
    pageTracker._trackPageview(frameName);
    switch (frameName)
	{
		case "/index.php":
        case "/creative-web-design.php":
			frameID = 0;
			break;

		case "/about-us.php":
            $('#mn-company a').addClass('current');
            if(staySame==1)
            {
               frameID = -1;
               staySame = 0;
            }
            else
            {
                frameID = 1;
            }
		    
			break;


        case "/company-team.php":
        case "/technology-partners.php":
        case "/corporate-social-responsability.php":
            $('#mn-company a').addClass('current');
            if(staySame==1)
                {
                     frameID = -1;
                     staySame = 0;
                }

            else 
                {
                    frameID = 1;
                }

                break;


		case "/web-solutions.php":
            $('#mn-services a').addClass('current');
			frameID = 2;
            break;

		case "/award-winning-web-design.php":
            $('#mn-awards a').addClass('current');
			frameID = 3;
			break;

		case "/digital-agency-jobs.php":
            $('#mn-jobs a').addClass('current');
			frameID = 4;
			break;

        case "/showcase.php":
            $('#mn-showcase a').addClass('current');
			frameID = 5;
			break;
            
        case "/blog.php":
		case "/news-internet-business-web-2008.php":
		case "/news-internet-business-web-2007.php":
		case "/news-internet-business-web-2006.php":
		case '/blog/index.php/marketing-case-study-sparks-direct':
		case '/blog/index.php/user-centred-design-solution-for-betting-giant':
		case '/blog/index.php/officecavalry-com-launches-with-a-bang':
            $('#mn-news a').addClass('current');
			frameID = 6;
			break;

		case "/web-contact.php":
            $('#mn-contact a').addClass('current');
			frameID = 7;
			break;

		case "/web-solutions-design.php":
        case "/user-centred-design.php":
        case "/top-web-design-company.php":
        case "/web-programming.php":
        case "/flash-applications-development.php":
        case "/cms-for-websites.php":
        case "/mobile-app-design.php":
        case "/tablet-app-design.php":

        $('#mn-services a').addClass('current');

        if(frameID == 8 )
            {
                 frameID = -8;
            }

        else if(frameID !=  -8 )
            {
                frameID = 8;
            }
               
			break;

		case "/online-brand.php":
        case "/web-logo-design.php":
        case "/web-copywriting.php":
        case "/website-animation.php":

            $('#mn-services a').addClass('current');

            if(frameID == 9 )
                {
                     frameID = -9;
                }

            else if(frameID !=  -9 )
                {
                    frameID = 9;
                }

                break;
			

        case "/search-engine-marketing-company.php":
        case "/organic-search-engine-marketing.php":
        case "/website-speed-optimisation.php":
        case "/search-engine-advertising.php":
        case "/google-analytics-implementation.php":
        case "/multivariate-testing.php":
        case "/email-marketing-management.php":
        case "/online-viral-marketing.php":
        case "/online-publicity.php":
        case "/corporate-e-cards.php":
        case "/user-experience-optimisation.php":
            $('#mn-services a').addClass('current');

            if(frameID == 10 )
                {
                     frameID = -10;
                }

            else if(frameID !=  -10 )
                {
                    frameID = 10;
                }
      
			break;

        case "/services-consultacy.php":
        case "/digital-consultancy.php":
        case "/web-market-research.php" :
        case "/website-analytics.php":
        case "/stakeholder-consultation.php":
        case "/qualitative-focus-groups.php" :
        case "/eye-tracking.php":
        case "/testing-usability.php":
        case "/website-surveys.php" :
        case "/competitor-research.php" :

            $('#mn-services a').addClass('current');

			if(frameID == 11 )
            {
                 frameID = -11;
            }

            else if(frameID !=  -11 )
            {
                frameID = 11;
            }

			break;

        case "/web-technology-company.php":
        case "/services-web-technology.php":
        case "/web-2.0-website-design.php":
        case "/social-media-development.php":
        case "/secure-web-hosting.php":
        case "/e-commerce-solutions-uk.php":
        case "/touch-screen-website.php":
        case "/software-as-a-service.php":

            $('#mn-services a').addClass('current');

			if(frameID == 12 )
            {
                 frameID = -12;
            }

            else if(frameID !=  -12 )
            {
                frameID = 12;
            }
			break;

		/* don't move the flash */
		case "user-centred-design":
		case "top-web-design-company":
		case "web-programming":
		case "flash-applications-development":
		case "corporate-e-cards":
		case "website-animation":
		case "ecommerce-solutions-uk":

		case "market-analysis":
		case "website-creative-brainstorming":
		case "web-logo-design":
		case "web-copywriting":

		case "e-commerce-solutions-uk":
		case "web-2.0-website-design":
		case "web-scalable-mysql-databases":
		case "social-media-development":
		case "secure-web-hosting":
		case "touch-screen-website":
		case "internet-tv-iptv":
		case "cms-for-websites":
		case "web-standard-usability-compliant":

		case "organic-search-engine-marketing":
		case "website-speed-optimisation":
		case "online-publicity":
		case "online-viral-marketing":
		case "search-engine-advertising":
		case "email-marketing-management":
            $('#mn-services a').addClass('current');
            frameID = -1;
			break;

        case "/job-technical.php":
        case "/job-creative.php":
        case "/job-marketing.php":
        case "/job-freelancer.php":
            $('#mn-jobs a').addClass('current');
            frameID = -1;
			break;
        
        case "/danny-bluestone.php":    staffId = 2;frameID = -1;break;
        case "/matt-gibson.php":        staffId = 3;frameID = -1;break;
        case "/sylvain-reiter.php":     staffId = 4;frameID = -1;break;
        case "/tom-hicks.php":          staffId = 5;frameID = -1;break;
        case "/lee-hsueh-chia.php":     staffId = 6;frameID = -1;break;

        case "/gareth-drew.php":		staffId = 7;frameID = -1;break;
        case "/john-hamelink.php":      staffId = 8;frameID = -1;break;
        case "/rajkumar-remanan.php":   staffId = 9;frameID = -1;break;
        case "/harry-clark.php":        staffId = 10;frameID = -1;break;

        case "/tomasz-tomczyk.php":     staffId = 11;frameID = -1;break;
        case "/tyrone-atiko.php":	    staffId = 12;frameID = -1;break;
        case "/karolina-pajewska.php":  staffId = 13;frameID = -1;break;
        case "/neil-dawson.php":		staffId = 14;frameID = -1;break;
        case "/ya-sheng-cheng.php":		staffId = 15;frameID = -1;break;
        case "/arpit-bajpai.php":		staffId = 16;frameID = -1;break;
		
        case "/siji-onabanjo.php":		staffId = 17;frameID = -1;break;
        case "/sangheethan-subramaniam.php":  staffId = 18;frameID = -1;break;
        case "/tauseef-mukhtar.php":	staffId = 19;frameID = -1;break;
		

		default :
            
            // don't move it we are in the news already
            if (frameName.match("/blog/index.php/"))
                {
                    frameID = -1;
                
                }
            else
                {
                   frameID = 0;
                }
			
			break;
	}

        
    //alert("going to "+frameID+" staff ID"+staffId);
        
	// Did we get the desired frame?
	if (frameID >= 0)
	{
        if(noFlash==false)
        {
            return setFlashMovieFrameId(frameID);
        }
        else
        {
            //swith static banner images
            return setBannerImage(frameID);
        }
	}
	else
	{
        if( staffId >0 )
        {
            $('#mn-company a').addClass('current');
            return setFlashMovieFrameIdStaff(staffId);
        }
        else
        {
            return false;
        }
		
	}
}

function setBannerImage(frameID)
{
    switch(frameID){
        case 0: bannerImage = 'banner.jpg';break;
        case 1: bannerImage = 'company-flash.jpg';break;
        case 2: bannerImage = 'services-flash.jpg';break;
        case 3: bannerImage = 'awards-flash.jpg';break;
        case 4: bannerImage = 'jobs-flash.jpg';break;
        case 5: bannerImage = 'web-production-flash.jpg';break;
        case 6: bannerImage = 'news-flash.jpg';break;
        case 7: bannerImage = 'contact-flash.jpg';break;
        case 8: bannerImage = 'web-technology-flash.jpg';break;
        case 9: bannerImage = 'branding-flash.jpg';break;
        case 10: bannerImage = 'online-marketing-flash.jpg';break;
        case 11: bannerImage = 'consultacy-flash.jpg';break;        
    }
    
    $('.top-banner').fadeOut('fast',function(){$('.top-banner').empty();});
    $('.top-banner').fadeIn('slow',function(){
        $('.top-banner').append('<img src="images/'+bannerImage+'" />');
    })
    
    
}


var max_slide_width = 720;
var max_slide_height = 204;
var max_slide_left = -453;


var min_slide_width = 267;
var min_slide_height = 204;
var min_slide_left = 0;

var curr_slide_width = 267;
var curr_slide_height = 204;
var curr_slide_left = 0;




function increase_size()
{

    if(curr_slide_width < max_slide_width)
        {
          curr_slide_width += 7;

          if(curr_slide_width > max_slide_width)
              {
                  curr_slide_width = max_slide_width;
              }
        }
   
   if(curr_slide_left > max_slide_left)
        {
          curr_slide_left -= 7;

          if(curr_slide_left < max_slide_left )
              {
                  curr_slide_left = max_slide_left;
              }
        }

    $('#slider2').css('left',curr_slide_left + 'px' );
    $('#slider2').css('width',curr_slide_width + 'px' );


    
   


   if(curr_slide_width < max_slide_width || curr_slide_left > max_slide_left )
       {
            setTimeout('increase_size()', 0);
       }

   else
   {
       increase_end();
   }


}

function decrease_size()
{
     if(curr_slide_width > min_slide_width)
        {
          curr_slide_width -= 7;

          if(curr_slide_width < min_slide_width)
              {
                  curr_slide_width = min_slide_width;
              }

        }

   if(curr_slide_left < min_slide_left)
        {
          curr_slide_left += 7;

          if(curr_slide_left  > min_slide_left )
              {
                  curr_slide_left =  min_slide_left;
              }
        }

    $('#slider2').css('left',curr_slide_left + 'px' );
    $('#slider2').css('width',curr_slide_width + 'px' );

      

    


   if(curr_slide_width > min_slide_width || curr_slide_left < min_slide_left )
       {
            setTimeout('decrease_size()', 0);
       }

       else
           {
               decrease_end();
           }
}


function increase_end()
{

}

function decrease_end()
{
    $('#carousel2').fadeIn(200);
    $('#slider2 .justzoom').remove();
    $('#zoom').attr('src','images/zoom.gif');
    $('#slider2').attr('opened',0);

    $('#slider2 .jcarousel-prev').show();
    $('#slider2 .jcarousel-next').show();
}

function zoomShow()
{
    inner = $('#slider2').html();
    if($('#slider2').attr('opened') == 1 )
    {

        /*
           $('#slider2').animate( {width:'267px', height:'204px', left:'0'}, 100,
                    function()
                    {
                    $('#carousel2').fadeIn(200);
                    $('#slider2 .justzoom').remove();
                    $('#zoom').attr('src','images/zoom.gif');
                    $('#slider2').attr('opened',0);
                    
                    $('#slider2 .jcarousel-prev').show();
                    $('#slider2 .jcarousel-next').show();
                    }
              );
          */

         $('#banner_link').hide();
         decrease_size();


    }
    else
    {
             $('#slider2 .jcarousel-prev').hide();
             $('#slider2 .jcarousel-next').hide();

             $('#carousel2').hide(100);

             //$('#slider2').css('border', '5px  solid #cccccc');

              $('#slider2').append($('<img onclick="zoomShow()"  id="bigimage"  class="justzoom" src="'+ cur_big_item.bigurl +'"/>').hide().fadeIn(700));
              

              $('#zoom').attr('src','images/zoomout.gif');
              $('#slider2').attr('opened',1);


            increase_size();

            $('#banner_link').attr('href', cur_big_item.href);
            $('#banner_link').show();

             /*
             $('#slider2').animate( {width:'720px', height:'204px',  left:'-465px' }, 100,

                    function()
                    {
   
                    }
              );
              */

             


        }

}


function initTip()
{
    $(".tooltip").remove();
    $("li.onEcom").attr('title','eCommerce/Online Store');
    $("li.onBranding").attr('title','Full online and offline branding including logo design');
    $("li.onFlash").attr('title','Incorporates Interactive/Animated Flash elements');
    $("li.onSearch").attr('title','Ongoing Search Engine Marketing');
    $("li.onCms").attr('title','Content Management System(CMS)');
    $("li.onAward").attr('title','Shortlisted or winner of Award');
    simple_tooltip(".feature-list li","tooltip");
}


function simple_tooltip(target_items, name){
$(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><div class='"+name+"-text'>"+$(this).attr('title')+"</div></div>");
		var my_tooltip = $("#"+name+i);
		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
		$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				var border_top = $(window).scrollTop();
				var border_right = $(window).width();
				var left_pos;
				var top_pos;
				var offset = 15;
				if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
					left_pos = kmouse.pageX+offset;
					} else{
					left_pos = border_right-my_tooltip.width()-offset;
					}

				if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
					top_pos = border_top +offset;
					} else{
					top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}

				my_tooltip.css({left:left_pos, top:top_pos});
		}).mouseout(function(){
				my_tooltip.css({left:"-9999px"});
		});

		}

	});

}



(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
    return this.each(function(i){
    var ah = $(this).height();
    var ph = $(this).parent().height();
    var mh = (ph - ah) / 2;
    $(this).css('padding-top', mh);
    });
};
})(jQuery);

var slide_path = 'images/slideshow/works/';

var bannerItems = {
    bam:{url: slide_path+ 'thumb-bam.png', title: '', href: 'http://www.bam.co.uk', bigurl: slide_path + 'bam.png'},
    /*banyan:{url: slide_path+ 'thumb-banyan.png', title: '', href: 'http://www.banyan-investments.com', bigurl: slide_path + 'banyan.png'},*/
    boonspace:{url: slide_path+ 'thumb-boonspace.jpg', title: '', href: 'http://www.boonspace.com', bigurl: slide_path + 'boonspace.jpg'},
    e2:{url: slide_path+ 'thumb-e2.png', title: '', href: 'http://www.e2research.com', bigurl: slide_path + 'e2.png'},
    gladstone: {url: slide_path+ 'thumb-gladstone.jpg', title: '', href: 'http://www.gladstonejewellery.com', bigurl: slide_path + 'gladstone.jpg'},
    oag:{url: slide_path+ 'thumb-oag.jpg', title: '', href: 'http://www.oag.uk.com', bigurl: slide_path + 'oag.jpg'},
    vinifera:{url: slide_path+ 'thumb-vinifera.jpg', title: '', href: 'http://www.viniferaboutique.com', bigurl: slide_path + 'vinifera.png'},
    ecard:{url: slide_path+ 'thumb-ecard.jpg', title: '', href: 'http://www.cyber-duck.co.uk/ecard2009', bigurl: slide_path + 'ecard.jpg'},
    fincorp:{url: slide_path+ 'thumb-fincorp.jpg', title: '', href: 'http://www.fincorp.co.uk', bigurl: slide_path + 'fincorp.jpg'},
    hablib:{url: slide_path+ 'thumb-hablib.png', title: '', href: 'http://www.hablib.com', bigurl: slide_path + 'hablib.png'},
    ukvisa:{url: slide_path+ 'thumb-uk-visa-appeal.png', title: '', href: 'http://www.uk-visa-appeal.co.uk', bigurl: slide_path + 'uk-visa-appeal.png'},
    hannah:{url: slide_path+ 'thumb-hannah.png', title: '', href: 'http://www.hannahmould.com', bigurl: slide_path + 'hannah.png'},
    holcyon:{url: slide_path+ 'thumb-holcyon.png', title: '', href: 'http://www.halcyongallery.com', bigurl: slide_path + 'holcyon.png'},
    jaa:{url: slide_path+ 'thumb-jaa-ecard.jpg', title: '', href: 'http://www.jaa-media.co.uk/christmascard/', bigurl: slide_path + 'jaa-ecard.jpg'},
    jaf:{url: slide_path+ 'thumb-jaf-ecard.jpg', title: '', href: 'http://www.cyberduck.net/simcomm/', bigurl: slide_path + 'jaf-ecard.jpg'},
    mobile:{url: slide_path+ 'thumb-mobile-app.jpg', title: '', href: 'http://www.wisteria.co.uk', bigurl: slide_path + 'mobile-app.jpg'},
    optima:{url: slide_path+ 'thumb-optima.jpg', title: '', href: 'http://www.optimasystems.com', bigurl: slide_path + 'optima.jpg'},
    paperround:{url: slide_path+ 'thumb-paper-round.jpg', title: '', href: 'http://www.paper-round.co.uk', bigurl: slide_path + 'paper-round.jpg'},
    periscopix:{url: slide_path+ 'thumb-periscopix.jpg', title: '', href: 'http://www.periscopix.co.uk', bigurl: slide_path + 'periscopix.jpg'},
    sterlingcard:{url: slide_path+ 'thumb-sterling-card.jpg', title: '', href: 'http://www.sterlingcard.co.uk', bigurl: slide_path + 'sterling-card.jpg'},
    syntaxin:{url: slide_path+ 'thumb-syntaxin.png', title: '', href: 'http://www.syntaxin.com', bigurl: slide_path + 'syntaxin.png'},
    syntaxineCard:{url: slide_path+ 'thumb-syntaxin-ecard.jpg', title: '', href: 'http://www.syntaxin.com/ecard/', bigurl: slide_path + 'syntaxin-ecard.jpg'},
    wisteria:{url: slide_path+ 'thumb-wisteria-formations.png', title: '', href: 'http://www.wisteriaformations.co.uk', bigurl: slide_path + 'wisteria-formations.png'},
    eu:{url: slide_path+ 'thumb-EU.jpg', title: '', href: 'http://www.the-eu-and-me.org.uk', bigurl: slide_path + 'EU.jpg'},
    duckPad:{url: slide_path+ 'thumb-duck-pad.jpg', title: '', href: 'http://www.cyber-duck.co.uk/ipad', bigurl: slide_path + 'duck-pad.jpg'},
    optimaPad:{url: slide_path+ 'thumb-optima-pad.jpg', title: '', href: 'http://www.optimasystems.com', bigurl: slide_path + 'optima-pad.jpg'},
    farHorizon:{url: slide_path+ 'thumb-far-horizon.png', title: '', href: 'http://www.thefarhorizons.com/', bigurl: slide_path + 'far-horizon.jpg'},
    nordicbet:{url: slide_path+ 'thumb-nordicbet.jpg', title: '', href: 'http://www.nordicbet.com/', bigurl: slide_path + 'nordicbet.png'}
};

function load_banners()
{

        if( $('#service-content #banner-area .slidediv').length == 0  &&   $('#service-content #banner-area .jcarousel-container').length == 0 )
        {
            $('#service-content #banner-area').html('loading...');
            $('#service-content #banner-area').load('default_banner.php');
        }

         if( $('#company-content #banner-area .slidediv').length == 0  &&   $('#company-content #banner-area .jcarousel-container').length == 0 )
        {
            $('#company-content #banner-area').html('loading...');
            $('#company-content #banner-area').load('default_banner.php');
        }

}


function carousel2_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, carousel2_itemList.length);
    carousel.add(i, mycarousel_getItemHTML2(carousel2_itemList[idx - 1]));
}

function carousel2_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
}

/**
 * Item html creation helper.
 */

function mycarousel_getItemHTML2(item)
{
    cur_big_item = item;
    /* return '<a href="'+ item.href +'" target="_blank" ><img src="' + item.url + '"  alt="' + item.title + '" /></a>'; */
    return '<a href="javascript:void(0);" onclick="zoomShow()" ><img src="' + item.url + '"  alt="' + item.title + '" /></a>';
}

function imageSlide(){
		$(".image-slide").cycle({
                        timeout: 5000,
                        delay: 2000,
                        loop:   true,
                        speed:  500,
                        cleartypeNoBg:   true
		});
}

function imageCarousel()
{
	$('.image-carousel').jcarousel({
		scroll:1,
		visible:1,
		buttonNextHTML:'<div class="next-carousel"></div>',
		buttonPrevHTML:'<div class="prev-carousel"></div>'

	});
}


