$(document).ready(function() { q.init() });

var q = {
	
	init : function() {
		if( $('#solutions').is('div') ) {
			q.solutionsInit();
		}
		
		$('.pages_wrapper').QBscroll();
		
		if( $('#flash_panic').is('div') && $.flash.hasVersion(9) ) {
			q.flash();
		}
		
		if( $('#social-media-links').is('div') ) {
			q.sm.init();
		}
	
	},
	
	/* SOCIAL-MEDIA FUNCTIONS */
	
	sm : {
		
		channels : new Array(),
		
		init: function() {
			q.sm.channels['sm-blog'] = new q.sm.channel('#sm-blog', '#sm-blog > a:first,#sm-blog > div:first');
			q.sm.channels['sm-facebook'] = new q.sm.channel('#sm-facebook', '#sm-facebook > a:first,#sm-facebook > div:first');
			q.sm.channels['twitter-tools'] = new q.sm.channel('#twitter-tools', '#twitter-tools > h2:first,#twitter-tools > div:first');
			q.sm.channels['sm-linkedin'] = new q.sm.channel('#sm-linkedin', '#sm-linkedin > a:first,#sm-linkedin > div:first');						

			// Twitter specific
			$('#twitter-tools ul > li:first').click(function() { window.location.href = $('#twitter-tools a.aktt_tweet_time').attr('href'); });
			$('#twitter-tools > h2').click(function() { window.location.href = $('#twitter-tools li.aktt_more_updates a').attr('href'); });
			$('#twitter-tools ul > li:first').append('<span class="img-frame"></span>');
		},
		
		hideAll: function() {
			for (var key in q.sm.channels) {
				q.sm.channels[key].visible = false;
				q.sm.channels[key].hide();				
			}
		},
		
		channel : function(container, triggers) {
			this.visible = false;
			this.container = $(container);
			this.triggers = triggers;
			$(this.triggers).hover(
				function() {
					var obj = q.sm.channels[$(this).parents('li:first').attr('id')];
					if( !obj.visible ) {
						q.sm.hideAll();
						if( !$(obj.container).hasClass('active') ) {
							$(obj.container).addClass('active');
							$('#footer').css('zIndex', 1000);
						}
						obj.visible = true;
					}
				},
				function() {
					var obj = q.sm.channels[$(this).parents('li:first').attr('id')];
					setTimeout(function() {
						obj.hide();
					}, 500);
					obj.visible = false;							
				}
			);
			this.hide = function() {
				if( !this.visible && $(this.container).hasClass('active') ) {
					$(this.container).removeClass('active');
					$('#footer').css('zIndex', 10);
				}						
			}
			return this;
		}
	},
	
	flash : function() {
	
		$('.flash_content').each( function(i) {
			
			s = jQuery.parseJSON( $(this).find('.vars').text() );
			w = $(this).width();
			h = $(this).height();					
			
	  	$(this).flash(
	  		{
	  			swf: s.src,
	  			width: w,
	  			height: h,
	  			flashvars: s.vars
	  		}
	  	);
	  	$('.no_flash').remove();
	  	
	  });		
	
	},
	
	solutionsInit : function() {
	
		// Solutions
		solutionWidth = $('#solutions li').width();
		numOfSolutions = $('#solutions li').length;
		$('#solutions').width( ( solutionWidth * numOfSolutions ) + ( 10 * ( numOfSolutions - 1 ) ) );
		$('#solutions li').each(function(i) {
			$(this).css('left', i * 120 );
		});
		$('#solutions li:last, #solutions li:eq(' + ( $('#solutions li').length - 2 ) + ')').addClass('last');
		$('#solutions li:last').css({
			left: 'auto',
			right: 0
		});
		$('#solutions li:eq(' + ( $('#solutions li').length - 2 ) + ')').css({
			left: 'auto',
			right: '120px'
		});		
		$('#solutions li').QBsolution();
		
		// Companies
		companiesWidth = $('#companies li').width();
		numOfCompanies = $('#companies li').length;
		$('#companies').width( ( companiesWidth * numOfCompanies ) + ( 10 * ( numOfCompanies - 1 ) ) );
		$('#companies li').each(function(i) {
			$(this).css('left', i * 240 );
		});
	}
}

jQuery.fn.fixClearType = function(){ 
    return this.each(function(){ 
        if(typeof this.style.filter  && this.style.removeAttribute) 
            this.style.removeAttribute("filter"); 
    }) 
} 

// Fix buttons in FF
$(document).ready(function() {
	if ( $.browser.mozilla == true ) {
		$('button#submit span').css({
			position: 'relative',
			top: '-1px',
			right: '-3px'
			
		});
	}
});


// Custom Archive Widget
$(function() {
    var month = 0;

    $('.custom-archive-posts-list').hide();

    $('.custom-archive-month-link').click(function(e) {

        if (month !== this) {
            $('.custom-archive-posts-list:visible').slideUp('fast');
            $('.custom-archive-posts-list', $(this).parent()).slideDown('fast');
        }

        month = this;
        e.preventDefault();
    });
});

