/*var tabName = '';
var selectedTab = -1;
function moveNext() {
	if($('.jcarousel-control .active').next().length>0) {
		if (selectedTab >= 0) {
			alert('Now cycling content area');
		} else {
			$('.active').next().addClass('active');
			$('.active').first().removeClass('active');
			$('#mask').css({display: 'none', height: $('.active_bottom').height()}).slideDown('slow');
			$('.active_bottom').next().addClass('active_bottom');
			$('.active_bottom').first().removeClass('active_bottom');
			$('.active_bottom').prev().slideToggle('slow');
			$('.active_bottom').slideToggle('slow');
			$('#mask').slideToggle('slow');
			// #bottomDetails
			$('.active_bottom').slideToggle('slow');
		}
	} else {
		$('.jcarousel-control a').first().addClass('active');
		$('.jcarousel-control a').last().removeClass('active');
		$('#mask').css({display: 'none', height: $('.active_bottom').height()}).slideDown('slow');
		$('.sliderContent').first().addClass('active_bottom');
		$('.sliderContent').last().removeClass('active_bottom');
		$('.sliderContent').last().slideToggle('slow');
		$('.active_bottom').slideToggle('slow');
		$('#mask').slideToggle('slow');
		$('.active_bottom').slideToggle('slow');
	}
}

function movePrev() {
	if($('.jcarousel-control .active').prev().length>0) {
		if (selectedTab >= 0) {
			console.log('Now cycling content area');
		} else {
			$('.active').prev().addClass('active');
			$('.active').last().removeClass('active');
			$('#mask').css({display: 'none', height: $('.active_bottom').height()}).slideDown('slow');
			$('.active_bottom').prev().addClass('active_bottom');
			$('.active_bottom').last().removeClass('active_bottom');
			$('.active_bottom').next().slideToggle('slow');
			$('#mask').slideToggle('slow');
			$('.active_bottom').slideToggle('slow');
		}
	} else {
		$('.jcarousel-control a').last().addClass('active');
		$('.jcarousel-control a').first().removeClass('active');
		$('#mask').css({display: 'none', height: $('.active_bottom').height()}).slideDown('slow');
		$('.sliderContent').last().addClass('active_bottom');
		$('.sliderContent').first().removeClass('active_bottom');
		$('.sliderContent').first().slideToggle('slow');
		$('#mask').slideToggle('slow');
		$('.active_bottom').slideToggle('slow');
	}
}

function moveAtIndex(el) {
	if (selectedTab < 0) {
		selectedTab = el;
	} else {
		selectedTab = -1;
	}	
	$('.jcarousel-control a').removeClass('active');
	$('.jcarousel-control a').eq(el).addClass('active');
	$('#mask').css({display: 'none', height: $('.active_bottom').height()}).slideDown('slow');
	$('.active_bottom').slideToggle('slow');
	$('.active_bottom').removeClass('active_bottom');
	$('.sliderContent').eq(el).addClass('active_bottom');
	$('#mask').slideToggle('slow');
	$('.active_bottom').slideToggle('slow');
}

function mycarousel_initCallback(carousel) {
	$('.jcarousel-control a').bind('click', function() {
		var el = $('.jcarousel-control a').index(this);
		carousel.scroll(jQuery.jcarousel.intval(el+1));
		moveAtIndex(el);
		return false;
	});
	
	$('#mycarousel-next').bind('click', function() {
		moveNext();	
		if (selectedTab < 0) {
			carousel.next();
		}
	    return false;
	});
	
	$('#mycarousel-prev').bind('click', function() {
		movePrev();
		if (selectedTab < 0) {
			carousel.prev();
		}
	    return false;
	});
};
*/
function show_tab(tabId) {
    tabName = tabId;
    $.ajax({
        type: "POST",
        url: base_url+"main/get_"+tabId,
        dataType: 'html',
        success: function(data){
            $('#overlay').css({
                background: 'url("'+base_url+'assets/images/gray_overlay.png")',
                zindex: '1',
                height: $('.page').height()
            });
            if ($.browser.msie  && parseInt($.browser.version) == 7) {
                $('#overlay').css('display', 'none');
            }
            
            $(".footer #"+tabId).addClass('active');
            $('#tabContent').html(data);
            $('#tabContent').css('display', 'block');
            $('.popWindow').css('z-index', '999');
            $('.popWindow').slideDown('slow');
            
            if(tabId!='contact' && tabId!='sitemap')
            {
                $('#pane1').jScrollPane();
                if (tabId == 'impressum')
                {
                    $('.impressumTabColumn2').attr('style','width:350px!IMPORTANT; float: left; height:500px; overflow: auto; padding: 0;');
                } 
            }
            	
                
        }
    });
}

function shitch_tab(tabId) {
    if($('#tabContent').children().length>0) {
        $('.popWindow').slideUp('slow', function() {
            $('#tabContent').html('');
            $(".footer a.active").removeClass('active');
            if(tabName != tabId) {
                show_tab(tabId);
            } else {
                $('#overlay').css({
                    background: 'none',
                    height: '0px'
                });
            }
        });
    }else{
        show_tab(tabId);
    }
}

function closePopUp() {
    $('.popWindow').slideUp('slow', function() {
        $('#tabContent').html('');
        $('#overlay').css({
            background: 'none',
            height: '0px'
        });
        $(".footer a.active").removeClass('active');
    });
}

function switch_menu_states(){
    var currentItem = $('.active');
    var currentItemId = currentItem.attr('id');
    var aux_arr = currentItemId.split('_');
    currentItemId = aux_arr[1];

    var current_prod = '';
    var link = location.pathname;
    if ((link != '/products') || (link != '/products/')){
       var current_prod_arr = link.split('/');
       current_prod = current_prod_arr[current_prod_arr.length - 1];
    }
    $('.submenu').hide();
    $('.submenu span').hide();
    $('.menu'+currentItemId).show();
    if (current_prod.search('product_') == 0) {
        var el = $('a.active span').css('display', 'block');

//        var idTemp = el.attr('id');
//        var index_arr_temp = idTemp.split('_');
//        var indexTemp = index_arr_temp[2];
        //carousel.scroll($.jcarousel.intval(indexTemp));
//        $('.productDetailsCls').hide();
//        $('#productDetails'+indexTemp).show();
    }
    

}

function openContactForm() {
    $.ajax({
        type: "POST",
        url: base_url+"main/get_contactForm",
        dataType: 'html',
        success: function(data){
            $('#overlay').css({
                background: 'url("'+base_url+'assets/images/gray_overlay.png")',
                height: $('.page').height()
            });
            $('#contact_form').html(data);
            $('#contact_form').css('display', 'block');
            $('.popWindow').slideDown('slow');
        }
    });
}
function closeContactForm() {
    $.ajax({
        type: "POST",
        url: base_url+"main/get_contact",
        dataType: 'html',
        success: function(data){
            $('#overlay').css({
                background: 'url("'+base_url+'assets/images/gray_overlay.png")',
                height: $('.page').height()
            });
            $('#contact_address').html(data);
            $('#contact_address').css('display', 'block');
            $('.popWindow').slideDown('slow');
        }
    });
}

function submitContactForm() {
    $.ajax({
        type: "POST",
        url: base_url+"main/saveContactFormular",
        dataType: 'html',
        success: function(data){
            $('#overlay').css({
                background: 'url("'+base_url+'assets/images/gray_overlay.png")',
                height: $('.page').height()
            });
            $('#contact_address').html(data);
            $('#contact_address').css('display', 'block');
            $('.popWindow').slideDown('slow');
        }
    });
}

$(document).ready(function() {
    $('#sitemaplink').live('click', function() {
        shitch_tab('sitemap');
    });
    $(".footer #footerMenuTable a").live('click', function() {
        var tabId = $(this).attr('id');
        shitch_tab(tabId);
    });

    switch_menu_states();

    $('.projectDescriptionTop').jScrollPane();
    var mouseOverActiveElement = false;

    $('.popWindow').live('mouseenter', function(){
        mouseOverActiveElement = true; 
    }).live('mouseleave', function(){ 
        mouseOverActiveElement = false; 
    });
    $("html").click(function(){ 
        if (!mouseOverActiveElement) {
            closePopUp();
        }
    });
    
    $("popWindow").attr('style','border: 1px red solid');
    
})


