
jQuery.fn.exists = function() {
	return jQuery(this).length>0; 
	}
		

var mask2load = new Array();
var mask_loc = '';
var mask_iterator = 0;

(function($){
	$('#jcarousel-menu li').each(function() {
		mask_loc = $(this).find('.device').attr('src').replace('pic_','mask_').replace('.png','.gif');
		mask2load[mask_iterator] = mask_loc;
		$(this).find('.display img').addClass('imask'+mask_iterator);
		mask_iterator++;
		});	
	})(jQuery);



var cookieName = 'fontSize';
var cookieOptions = {expires: 100000, path: '/'};

function textSize(fontSize) {
	$('body').css({'font-size': fontSize});
	$.cookie(cookieName, fontSize, cookieOptions);
	}
	

var count = 0;
	
function menu_initCallback(carousel) {

	count = carousel.options.size / 3;

    carousel.clip.hover(
		function() { carousel.stopAuto() },
		function() { carousel.startAuto()}
		);
		
	$('#jcarousel-menu-next').bind('click', function() {
		carousel.next();
		
		return false;
		});

	$('#jcarousel-menu-prev').bind('click', function() {
		carousel.prev();
		return false;
		});	
		
	carousel.clip.mousewheel(function(event, delta) {
		delta < 0 ? carousel.next() : carousel.prev();
		return false;
        });
		
	Cufon.refresh('.menu-main-extend a'); 
	};
	
	
function menu_itemCallback(carousel, state) {
	var current_item = 0;
	
	$("#jcarousel-menu li").each(function(){
		if ($(this).offset().left >= 0){
			current_item = $(this).index();
			return false;
			}
		});
	 
	if(current_item==(count*2) && state=='next') carousel.scroll(1,false);
	else if(current_item==0 && state!='next') carousel.scroll((count + 1),false);
	
	}
	
	
function gallery_initCallback(carousel) {
	
	carousel.clip.hover(
		function() { carousel.stopAuto() },
		function() { carousel.startAuto()}
		);
			
	$('#jcarousel-gallery-next').bind('click', function() {
		carousel.next();
		return false;
		});

	$('#jcarousel-gallery-prev').bind('click', function() {
		carousel.prev();
		return false;
		});	
		
	};		
	

$(window).load(function() {

	$(".icon-mail").fancybox({
		'overlayColor'		: '#58c4c6',
		'overlayOpacity'	: 0.8,
		'centerOnScroll'	: true,
		'width'				: '90%',
		'height'			: '90%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	$("#extend-btn a").click(function(e) {
		e.preventDefault();
		$("#extend").animate({'height':'toggle', 'opacity':'toggle'}, 400);
	})

	
	if($("select").exists())  {
		$("select").selectBox();
		}
	
	
	
	
	
	var menu_height = $('#jcarousel-menu').height();
	var margin_top = 0;
	
	
	
	
	
	$('#jcarousel-menu').append($('#jcarousel-menu').html().concat($('#jcarousel-menu').html()));
	Cufon.replace('.menu-main-extend a',{ fontFamily: 'Sketch Rockwell' });

	/*
	$('#jcarousel-menu a').hover(
		function() {
			coords_x = $(this).offset().left;
			coords_y = $(this).offset().top;
			$('.tooltip-body').html($(this).parent().find('.tooltip-txt').html());
			$('.tooltip').animate({opacity: 'show', top: (coords_y-65)+'px', left: (coords_x-25)+'px' }, 300);
			},
		function() {
			$('.tooltip').fadeOut(150);
			}
		);
	*/
	var start_item_length = $('#jcarousel-menu li').length;
	
	if($("#jcarousel-menu").exists())  {
		$("#jcarousel-menu").jcarousel({
			auto: 10,
			scroll: 1,
			wrap: 'both',
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: menu_initCallback,
			itemLoadCallback: menu_itemCallback
		})};
		
		
	if($('#jcarousel-gallery').exists()) {
		$("#jcarousel-gallery").jcarousel({
			auto: 5,
			scroll: 1,
			wrap: 'circular',
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: gallery_initCallback
    	})};
			
	$('#jcarousel-menu li').each(function(index, element) {
		margin_top = menu_height - $(this).height()-76 + Math.floor(Math.random()*30);
		$(this).css({'margin-top':  margin_top + 'px'});
		$(this).find('a').css({'bottom': Math.floor(Math.random()*60) +20 + 'px'});
		$(this).show();
		
	});

	$('.simple-box p:last').css({'background':'none', 'padding-bottom':'9px'});
		
	})
