function toggleSlidePanel() {
    $('#quickContact').click();
}

$(function() {
    try {
    // tooltip
    $("a.tip").tooltip({ 
        bodyHandler: function() { 
            return $(this).nextAll('span.tip').eq(0).html(); 
        }, 
        showURL: false 
    });
    
    
 // homepage faders 
    if($('#slidesTestimonials').length) {
        $('#slidesTestimonials').cycle({
            fx:             'fade',
            slideExpr:      'div.homeboxSlide',
            timeout:        8000,
            continuous:     true,
            pause:          true
        });
    }
    
    // accordion
    if($('#accSection').length) {
        $('#accSection').accordion({
            autoheight: false,
            collapsible: true,
            header: 'h6',
            active: false,
            animated: false
        });
    }
    
	// Cufon 
	if(typeof Cufon != 'undefined') {
		Cufon.replace("#caseStudyTitle");
	}
	
	// main slideshow
	$('#slidesWrapper').carousel('#prevSlide', '#nextSlide');
	
	// team slideshow
	$('#teamSlidesWrapper').carousel('#teamPrevSlide', '#teamNextSlide');
	
	$('#keyTeamMembers a').bind('click',function(){
		var pos = $(this).parent('li').prevAll('li').length;
		$('#teamSlidesContainer').animate({'left':'-'+parseInt(pos*401,10)+'px'});
		return false;
	});
	
	$('a.openChatWindow').bind('click', function(){
		window.open('http://a1.websitealive.com/456/rRouter.asp?groupid=456&amp;websiteid=0&amp;departmentid=0&amp;dl='+escape(document.location.href),'','width=400,height=400');
		return false;
	});
	
	// homepage small-slideshow
	$('div.homeBoxContent ul a').bind('mouseover', function(){
		var tm		= $(this).parents('ul').data('tm');
		var pos 	= $(this).parent('li').prevAll('li').length;
		var slides	= $(this).parents('#homeSolutions, #homeTools');
		
		clearTimeout(tm);
		
		tm = setTimeout(function(){
			$('div.slideItems', slides).animate({top: '-'+parseInt(pos*110,10)+'px'});
		}, 600);
		
		$(this).parents('ul').data('tm', tm);
		
		return false;
	});
	
	// homepage small-slideshow cancel 
	$('div.homeBoxSlideshow').bind('mouseover', function(){
		var tm = $(this).prev('div.homeBoxContent').find('ul').data('tm');
		if(tm) {
			clearTimeout(tm);
		}
	});
	
	// topPanel 
	$('#quickContact').bind('click', function(){
	    var cm = parseInt($('#slidePanel').css('marginTop'),10);
	    $('#slidePanel').animate({'marginTop': (cm !== 0 ? 0 : -205)});
		return false;
	});
		
	// topPanel - other triggers 
	$('a.toggleSlidePanel').bind('click', function(){
		$('html').animate({scrollTop:0},{complete:function(){
		    var cm = parseInt($('#slidePanel').css('marginTop'),10);
		    cm !== 0 && $('#slidePanel').animate({'marginTop': 0})
		}});
		return false;
	});
		
	$('#spSendMail').bind('click', function(e){
		var email 	= $('#iEmail', $('#spContactForm')).val();
		var content	= $('#iContent', $('#spContactForm')).val();
		
		content	= "User e-mail:\r\n"+email+"\r\n\r\nUser address:\r\n"+content;
		$(this).attr('href', 'mailto:hello@securevirtual.com?subject='+encodeURIComponent('Website contact form')+'&body='+encodeURIComponent(content));
		return true;
	});
	
	// print button
	$('li.toolPrint a').bind('click', function(){
		window.print();
		return false;
	});
		
	var fancyboxDefaults = {
		'width'				: 900,
		'height'			: parseInt(screen.availHeight - 400,10),
		'autoDimensions'	: false,
		'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		//'type'				: 'ajax',
		'overlayOpacity'	: '0.6',		
		'overlayShow'		: true,
		'overlayColor'		: '#FBB021',
		'imageScale'		: true,
		'padding'			: 0,
		'hideOnContentClick':false
	};
	
	//console.debug(fancyboxDefaults);
	
	// fancybox
	$('a.fb, a.fbn').fancybox(fancyboxDefaults);
	
	$('a.fbyt').bind('click', function(){
		var href = $(this).attr('href');
		var guid = href.split('?v=').pop();
		var ytid = 'fbyt-'+guid;
		
		if($('#'+ytid).length) { return false; }
		
		var html = '<div id="'+ytid+'" style="display:none;width:425px;height:355px;">'
				+ '<object width="425" height="355">'
				+ '<param value="http://www.youtube.com/v/'+guid+'" name="movie" />'
				+ '<param value="transparent" name="wmode" />'
				+ '<embed width="425" height="355" wmode="transparent" type="application/x-shockwave-flash" src="http://www.youtube.com/v/'+guid+'" />'
				+ '</object></div>';
		
		var fbSettings = jQuery.extend(fancyboxDefaults,{frameWidth:425,frameHeight:355});
		
		$(this).after(html).attr('href','#'+ytid).fancybox(fbSettings).click();
		return false;
	});	
	
	// FAQ
	$('#faqQuestions a').bind('click', function(){
		$('#faqQuestions a').removeClass('current');
		$(this).addClass('current');
		
		var answer = $(this).attr('href').split('#').pop();
		$('#faqAnswers').children('div:visible').fadeOut('fast', function(){
			$('#'+answer).fadeIn('slow');
		});
		
		
		return false;
	});
	
	// Home - affilates -> assign bg image
	$('#affilates a').each(function(i){
		$(this).css('backgroundPosition','0px -'+(i*47)+'px');	
		//if(i > 2) { $(this).hide(); }
	});
	// Home - affilates -> rollovers
	$('#affilates a').bind('mouseover mouseout', function(e){
		var bgpos = $(this).css('backgroundPosition').split(' ');
		$(this).css('backgroundPosition', (e.type=='mouseout'?'0':'-127px')+' '+bgpos[1]);
	});
	// Home - affilates -> carousel
	$('#affilates').data('i',1).data('m', $('#affilates li').length).data('p',$('#affilates li').slice(0,3));
	$('#affilates li').slice(0,3).fadeIn('slow').parent('ul').css('background','none');
	if($('#affilates').length) {
		setInterval(function(){
			var i = $('#affilates').data('i');
			var m = $('#affilates').data('m');
			var p = $('#affilates').data('p');
			var ob = i * 3;
			var oe = ob + 3;
			
			if(p!==null) {
				$(p).fadeOut('slow');
			} 
			$('#affilates li').slice(ob,oe).fadeIn('slow');
			
			if(oe >= m) {
				ob = 0;
				i  = -1;
			}
			++i;
			$('#affilates').data('i',i).data('p',$('#affilates li').slice(ob,oe));
		}, 4000);
	}
    } catch(e) {
        console.debug(e);
        
    }
});