/**
 * @package Promo HQ
 * @author Bonsai Media / Christian Duller
 * @version 1.0
 * @copyright 2011, Bonsai Media
*/

/* Promo HQ object which contains all our functions/etc */
var obj = obj || {};

/* document ready.... magic happens here */
$(document).ready(function(){
	obj = new jquery_main(); 
	obj.init();
});

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////


jquery_main = function() {
	// default values
	this.settings = {	
	};
	
	/**
	 * Initialise the Promo HQ website and various features.
	 */
	this.init = function() {
		this.initCufon();
		
		if($("#flash_banner").length){
			flashembed("flash_banner", 
			{
				src: "flash/slideshow.swf?"+Math.random(), 
				wmode: 'transparent',
				flashvars: 'xmlpath=flash/slideshow.xml'
			});
		}
		//this.menu();
	};
	
	/** 
	 * Initialise Cufon text replacement
	 */
	this.initCufon = function(){
		Cufon.replace('.login label, #banner h2, .right_panel h3, .special h4');
	};
	
	/** 
	 * Initialise menu
	 */
	this.menu = function() {
		$("#menu li").hover(
			function(){
				$("ul", this).fadeIn("fast");
					$('.m_nav',this).css({'border-top':'4px solid #479CB3',
								'color':'#097b99'});
				}, 
			function() {
					if(!$('.dflt',this).length){
						$('.m_nav',this).css({'border-top':'4px solid #fff',
									'color':'#000'});
					}
				} 
		);
		if (document.all) {
			$("#menu li").hoverClass ("sfHover");
		}
	};
	
	/** 
	 * create home page slideshow
	 */
	this.slideSwitch = function(elem) {
		function animate(){
			var $active = $(elem+' img.active');			
				if ( $active.length == 0 )  $(elem+' img:last');	
			var $next =  $active.next().length ? $active.next(): $(elem+' img:first');
						
			$active.addClass('last-active');
						
			$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function(){
					$active.removeClass('active last-active');
				});
		};
		// init
		var timeout;
			timeout = setInterval(function(){
					animate();
			},8000);
	}
	
	/**
	 * Initialise all colorbox popups
	 */
	this.initColorbox = function() {
		//$("a[rel='cpopup']").colorbox();
		if ($('.print_info').length) {
			$('.print_info').colorbox({width:"900px", height:"90%", iframe:true});
		}
		if ($('.outside').length) {
			$('.outside').colorbox({width:"900px", height:"400px", iframe:true});
		}
		if ($('.zoom').length) {
			$('.zoom').colorbox();
		}
		if ($('.pymnt_lnk').length) {
			$('.pymnt_lnk').colorbox({width:"900px", height:"550px", iframe:true});
		}
	};
	
};

/** 
 * Initialise menu
 * hover class
 */
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};
