var tabs,
    tabulation = false,
    initialTab = 'home',
    navSelector = '#tabs .ui-tabs-nav',
    navFilter = function(el) {
        return $(el).attr('href').replace(/^#/, '');
    },
    panelSelector = '#tabs .ui-tabs-panel',
    panelFilter = function() {
        $(panelSelector + ' a').filter(function() {
            return $(navSelector + ' a[title=' + $(this).attr('title') + ']').size() != 0;
        }).each(function(event) {
            $(this).attr('href', '#' + $(this).attr('title').replace(/ /g, '_'));
        });
    };

if ($.address.value() == '' || $.address.value() == '#') {
    $.address.value(initialTab);
}

// Address handler
$.address.history(false).strict(false).wrap(true).init(function(event) {
    // Adds the ID in a lazy manner to prevent scrolling
    $(panelSelector).attr('id', initialTab);

    $('a[rel=nav]').add(".main-menu li a").address(function() {
        return navFilter(this);
    });

    //panelFilter();

    // Enables the plugin for all the content links

    // Tabs setup
    tabs = $('#tabs')
        .tabs({
            fx: {
                opacity: 'toggle',
                duration: 'slow'
            }
        })
        .css('display', 'block');

    //$(navSelector).address();


}).change(function(event) {
	//nav slide
	//alert(event.value);
	if(event.value==""){
		thisValue = "";
	} else if (event.value != null){
		thisValue = event.value;
	} else {
		thisValue = "";
	}
	thisValue += "";
	if(thisValue != 'home') {
		if(thisValue.length != '0'){
			$('.menu_wrap').animate({
				top: '114px'
			}, 'slow');
		}
	}else{
		$('.menu_wrap').animate({
			top: '0px'
		}, 'slow');
	}
	//nav active
	$('.menu_wrap li[value="1"]')[0].value = 2;
	if($('.menu_wrap li a[title="'+thisValue+'"]').length > 0)
		$(".menu_wrap li a[title="+thisValue+"]").parent().attr('value', '1');
    else
		$(".menu_wrap li").eq(0).attr('value', '1');
		
	menuSlider.init('slider','slide');
	
    if($(".ui-tabs-nav li a[title="+thisValue+"]").length)
      bg=event.value+"_bg.jpg";
    else
      bg="home_bg.jpg";
    $("img.source-image").fadeOut(function(){
        $(this).attr('src','wp-content/themes/SalonCollage/library/images/backgrounds/'+bg).fadeIn();
      });

    var current = $('a[href=#' + thisValue + ']:first');
    
    // Sets the page title
    $.address.title($.address.title().split(' | ')[0] + ' | ' + current.text());

    // Selects the proper tab
    tabs.tabs('select', current.attr('href'));

}).history(true);

// Hides the tabs during initialization
document.write('<style type="text/css"> #tabs { display: none; } </style>');
$(function(){
	// Contact page map - click action
	$('#tabs').after('<div id="hijaxContent"></div>');
	$('a.nextpostslink, a.previouspostslink, a.hijax').live('click', function(){
	   if($(this).attr('id')!=undefined){
		window.location.hash = window.location.hash +'/'+$(this).attr('id');
	   }
		$('#hijaxContent').load($(this).attr('href'), function(){
		   $('#tabs').not('#hijaxContent #tabs').css('display', 'none');;
		   $('#hijaxContent').css('display', 'block');
		});
		return false;
	 });
	
	
	$(".thumb").live({
		'mouseenter':function(){
			$(this).find("img").fadeOut();
			return false;
		}, 'mouseleave': function() {
			$(this).find("img").fadeIn();
			return false;
		}
	});
	$('.goback a').live('click', function(){
	   $('#tabs').not('#hijaxContent #tabs').css('display', 'block');
	   $('#hijaxContent').css('display', 'none');
	   if($(this).attr('id')!=undefined){
			window.location.hash = $(this).attr('id');
	   }
	   return false;
	});
	$('.main-menu li a').live('click',function(){
	   $('#tabs').not('#hijaxContent #tabs').css('display', 'block');;
	   $('#hijaxContent').css('display', 'none');
	});
	$("img.prodImg").live('mouseenter',function(){
		$(this).parent().parent().find(".lineDescr").show();
	});
	$("img.prodImg").live({
		'mouseenter':function(){
			$(this).parent().parent().find(".lineDescr").css('display', 'block');
			return false;
		}, 'mouseleave': function() {
			$(this).parent().parent().find(".lineDescr").hide();
			return false;
		}
	});
						  
						  
						  
						  
	
	
});

