﻿/*function log(v) { if(typeof console != "undefined") { if (typeof console.debug != "undefined") { console.log(v);}}}*/
function log(v) { return true; }
	var hideAnnounce = function() {
		$('.jcarousel-mainbanner').jCarouselLite({ auto:4000, speed: 500, circular: true, vertical: true });
		$('.announce').fadeOut(2500);
	}

$(document).ready(function(){

	Cufon.replace('h1, h1.pageTitle, h2, h3, #products-menu li, #mainmenu li, .link, .button, .linktomenu, .linktoarchive'); // Works without a selector engine

	// analytics
	$.ga.load("UA-15136406-1");
	//$.ga.trackPageview();
	
	/* Set Popup alias Facebox */
	$('a[rel*=facebox]').facebox().click( function() {
		$.ga.trackEvent('downloads', $(this).attr('title'), $('.pageTitle').text()); // load into analytics
		log('Download, ' + $(this).attr('title') + ', ' + $('.pageTitle').text());
		return false;
	});

	$(".popup").draggable();

	$('#sSearch .button').click(function () {
		var searchFormMargin = $('#searchform').css('marginTop');
		$('#searchform').animate({marginTop: (($('#searchform').css("marginTop") < "0px") ? '0px' : searchFormMargin) });
		return false;
    });				

	$('#right-menu, #product_drawer').accordion({ header: "h3", autoHeight: false });
	$('#right-menu').accordion('activate', 1);

	$('#catProducts li').each(function(elm) {
		if($(this).text().substr(0,1) == '-') {
			text = $(this).text();
			$(this).css('width', '100%').append('<h2>' + text + '</h2>');
			$(this).find('a').remove();
		} else {
			productLink = $(this).find('a');
			productName = $(this).find('a').text();
			productLink.html('<img class="catProductsLiImg" src="./UserFiles/Image/Products/Overview/' + productName + '.jpg" /><div class="imgOverlay"><div class="imgMovement"></div></div><span>' + productName + '</span>');
		}
	});
	
	$('#catProducts li').hover(function() {
		if($(this).text().substr(0,1) == '-') return false;	
		$(this).find('.catProductsLiImg').fadeTo("normal", 1.0);
		$(this).find('.imgMovement').animate( {marginTop: '90px'}, 700).animate( {marginTop: '-200px'}, 1 )
	}, function() {
		$(this).find('.catProductsLiImg').fadeTo("slow", 0.4);
	});
	
	$('.jcarousel-sidebanner').jCarouselLite({ speed: 8000, auto:1, circular: true, scroll:4, index: 4 });
	//$('#page').after('<div class="pageCorner"><a rel="facebox" href="getdownloadlist.php?product=EB500TFT&type=dwl&holdname=1"><img src="images/highlite_corner_eb500tft_firmware_20100507.png"></a></div>'); 
	$("#sociable a").click(function(){ 
		$.ga.trackEvent('sociables', $(this).attr('title'), $('.pageTitle').text()); // load into analytics
		log('Sociables, ' + $(this).attr('title') + ', ' + $('.pageTitle').text());
		this.href=this.href.replace(/\[URL\]/g,encodeURIComponent(window.location.href)).replace(/\[POST\]/g,$('.pageTitle').text()); 
		this.target="_blank"; 
	});
	setTimeout('$("#mainmenu").lavaLamp({ fx: "easeOutCubic" });', 1000);
	setTimeout('hideAnnounce();', 3500);
/*	$('.announce').delay(500).fadeOut(150);
	$('.fade-fr-1').delay(700).fadeIn(150);
	$('.fade-fr-2').delay(900).fadeIn(150);
*/	
});
