$(document).ready(function() {
        
        if(typeof navigation_handler == 'object') {
            navigation_handler.setup();
        }
        
        if(typeof contact_data == 'object') {
            contact_data.setup();
        }
        
        $('a').map(function(i, el){
            if($(el).attr('rel') == 'external') {
                $(el).attr('target', '_blank');
            }
        });
        
      /*  $('.answer a').live('click', function() {
     		window.location($(this).attr('href'));
     	});
        
		$('.how-to-page .collapsible li .answer').hide();
		$('.how-to-page .collapsible li a').live('click', function() {
			$(this).parent().children('.answer').slideToggle('fast');
			return false;	
		});*/
		
		$("a[rel=photo]").fancybox({
			'titleShow'		: true,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		
		/*
		$(".request-estimate").fancybox({
			'titleShow'		: false,
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'width'			: 683,
			'height'		: 490,
			'type'			: 'iframe'
		});
		*/
		
		$('#panels-clickable li').click(function(){
			var href = $(this).children('a').attr('href');
			window.location = href;
		}).css({"cursor" : "pointer"});
		
		$li_num = $('.product-page .carousel ul li').size();
				
		$carousel_num = $('.product-page .carousel ul li.current').attr('rel');
		
		if($carousel_num >= 1 && $carousel_num <= 4) {
			$page = 1;
		} else if($carousel_num >= 5 && $carousel_num <= 8)
			$page = 2;
		else if($carousel_num >= 9 && $carousel_num <= 12)
			$page = 3;
		else if($carousel_num >= 13 && $carousel_num <= 16)
			$page = 4;
		else if($carousel_num >= 17 && $carousel_num <= 20)
			$page = 5;
		else if($carousel_num >= 21 && $carousel_num <= 24)
			$page = 6;
		else
			$page = 1;
		
		$('.carousel').carousel({
			page: $page
		});
		
		if($li_num >= 1 && $li_num <= 4) {
			$('.arrow.back').hide();
			$('.arrow.forward').hide();
		}
				
		var url = String(window.location);
		if(url.match(/showroom/))
			$('#content').css('min-height', $('#layout #navigation li.first-child ul').height() + 410);
		else
			$('#content').css('min-height', $('#layout #navigation li.first-child ul').height());
		
		$('.slide-reel').css('clear', 'both');

});

var win=null;
function printIt(printThis) {
	win = window.open();
	self.focus();
	win.document.open();
	win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
	win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
	win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
	win.document.write(printThis);
	win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
	win.document.close();
	win.print();
	win.close();
}


var navigation_handler = {
    items: [],
    
    setup: function()  {
        this.items = $('#navigation').children();

	$(this.items).bind('mouseover', function(event) {

            var subitems = $('ul', event.currentTarget);
            
            navigation_handler.items.map(function(i, el){
                if($(event.currentTarget) != el) {
                    $(el).removeClass('over');    
                }
            })

            if((subitems.length == 0 && $(event.currentTarget).attr('id') != 'nav-showroom' && $(event.currentTarget).attr('id') != 'nav-contact') || $(event.currentTarget).hasClass('first-child')) return;

            if($(event.currentTarget).hasClass('first-child')) {
               $(event.currentTarget).addClass('first-over');
            }
            if($(event.currentTarget).hasClass('last-child')) {
               $(event.currentTarget).addClass('last-over');
            }
            
            $(event.currentTarget).addClass('over');

	});        


	$('body').bind('mouseover', function(event) {
            if($(event.target).parents('#navigation').length > 0) return;
            navigation_handler.items.map(function(i, el){
                $(el).removeClass('over');
                $(el).removeClass('first-over');
                $(el).removeClass('last-over');
            })
	});        

    }
}


var contact_data = {
    items: [],
    
    setup: function()  {
        this.items = $('#contact-data li');

	$(this.items).bind('mouseover', function(event) {

            contact_data.items.map(function(i, el){
                if($(event.currentTarget) != el) {
                    $(el).removeClass('over');    
                }
            })
            
            $(event.currentTarget).addClass('over');

	});        


	$('body').bind('mouseover', function(event) {
            if($(event.target).parents('#contact-data').length > 0) return;
            contact_data.items.map(function(i, el){
                $(el).removeClass('over');
            })
	});        
	/*
	$('body').bind('click', function(event) {
            var related_a = $('a', event.target);
            if(related_a.length > 0) {
                window.location = related_a.attr('href');
            }
	});        
	*/
    }
}

