﻿$(function() {
    $('body').removeClass('no-js').addClass('js');

    $('a[rel*=external]').click(function() {
        window.open(this.href);
        return false;
    });

    $('a.email[rel]').each(function() {
        e = this.rel.replace('/', '@');
        this.href = 'mailto:' + e;
        $(this).text(e);
    });
    
    $('.carousel').attr('unselectable','on').css('MozUserSelect','none');

    // v 2.0
    $('form:has(input[type=submit])').each(function() {
        var thisForm = $(this);
        var submitButton = thisForm.find('input[type=submit]');
        var link = $('<a href="#" class="submitReplacement" title="' + submitButton.attr('value') + '">' + submitButton.attr('value') + '</a>');
        link.insertAfter(submitButton).click(function() {
            thisForm.submit();
            return false;
        });
        submitButton.remove();
    });
    
    //$(".raty").colorbox({iframe:true, innerWidth:650, innerHeight:500});
    $('.raty').click(function() {
        window.open(this.href, width=650, height=400, resizable='yes', scrollbars='no', menubar='no');
        return false;
    });

    // Cufon
    Cufon.replace('#nav a', { fontFamily: 'Myriad-Pro-Semibold'});
    Cufon.replace('#sidebar h2, .header h1, .contact .form h2, .home .big-box h1, .home .big-box .title', { fontFamily: 'Myriad-Pro-Light'});
    Cufon.replace('#sidebar h2 strong, .header h1 strong, #top .slogan, .home .big-box h1 strong', { fontFamily: 'Myriad-Pro-Regular'});

    Cufon.replace('#top .slogan, .contact .form .submitReplacement', { fontFamily: 'Myriad-Pro-Regular'});
    Cufon.replace('#top .slogan strong', { fontFamily: 'Myriad-Pro-Semibold'});

    Cufon.replace('.details .cont p, .details .description .tabs a ', { fontFamily: 'Myriad-Pro-Regular'});
    Cufon.replace('.details .description .tabs .active a, .details .cont p strong', { fontFamily: 'Myriad-Pro-Semibold'});
    Cufon.replace('.details .yourdata h2, .details .yourdata .submitReplacement, #faq h2,  .default h2 span, .details h2 span', { fontFamily: 'Myriad-Pro-Semibold'});

    // Q&A rozwijanie
    $('.qa dd').hide();
    $('.qa dt').click(function() {
        var toToggle = $(this).next();
        if (toToggle.is(':visible'))
        {
            $(this).removeClass('expanded');
            toToggle.slideUp('fast');
        }
        else
        {
            $(this).addClass('expanded');
            toToggle.slideDown('fast');
        }
    });

    //jCarousel

    function mycarousel_initCallback(carousel) {
        jQuery('#imgNext').bind('click', function() {
            carousel.next();
            return false;
        });
        jQuery('#imgPrev').bind('click', function() {
            carousel.prev();
            return false;
        });
    };
    
    $('#carousel').jcarousel({
        auto: 0,
        wrap: 'both'
    });

    $('#imgCarousel').jcarousel({
        auto: 0,
        scroll: 3,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });

    //Filter-select
    $('#filter select').sSelect({ ddMaxHeight: '300px'});
    
    //Filter - tabs
	$("#filter .tab-content").hide();
	//$("#filter .tabs li:first").addClass("active").show(); //Activate first tab
	
	var i = $('#filter div.active input').val();
	
	if(i == 1)
		$("#filter #filterTab1").show(); //Show first tab content
	else if(i == 2)
		$("#filter #filterTab2").show(); //Show first tab content
	else if(i == 3)
		$("#filter #filterTab3").show(); //Show first tab content	
	
	//$("#filter .tab-content:first").show(); //Show first tab content
	
	$("#filter .tabs li").click(function() {
		$("#filter .tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$("#filter .tab-content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

    //Produkt - tabs
	$("#productTabs .tab-content").hide();
	$("#productTabs .tabs li:first").addClass("active").show(); //Activate first tab
	$("#productTabs .tab-content:first").show(); //Show first tab content
	$("#productTabs .tabs li").click(function() {
		$("#productTabs .tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab

        Cufon.replace('.details .description .tabs a ', { fontFamily: 'Myriad-Pro-Regular'});
        Cufon.replace('.details .description .tabs .active a ', { fontFamily: 'Myriad-Pro-Semibold'});

		$("#productTabs .tab-content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

    //Filter-select
   // $('#filter select').sSelect({ ddMaxHeight: '300px'});

    // Product details contact form
    $('#infoPhone').placeholder();
    $('#infoEmail').placeholder();

    // Product details contact select
    $('#infoHours').sSelect({ ddMaxHeight: '300px'});
    
    
	var $slide = $('#slide');
	$slide.cycle({
		timeout: 10000,
		fx: 'scrollLeft',
		speed: 300,
		before: function(curr, next){
			$slide.css('background', 'url(' + $(next).attr('src')+ ')');
			$('#slideDescriptions').children().eq( $(curr).index() ).fadeOut(600);
			$('#slideDescriptions').children().eq( $(next).index() ).fadeIn(600);},
		pager: '#slideNav',
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><a href="#">' + $('#slide').children().eq( idx ).attr('alt') + '</a></li>';
		}
	});
	$('#slideNav').find('a').click(function(){
		$slide.cycle($(this).parent().index());
		return false;
	});
	
	$('.form-selectTV').change(function(){
		$('#TV').submit();
	});
	
	$('.form-selectAudio').change(function(){
		$('#Audio').submit();
	});
	
	$('.form-selectUrzedzenia').change(function(){
		$('#Urzadzenia').submit();
	});	
	
	$('.selectedTxt').truncate({
	    width: 90,
	    after: '&hellip;',
	    center: false,
	    addclass: false,
	    addtitle: false
	});
	
	
	$('#projektor-button a').click(function(){
		if ($('#projektor-content').is(':visible')) 
			$('#projektor-content').animate({width: 'hide'});
		else
			$('#projektor-content').animate({width: 'show'});
		return false;
	});
	
	$('#fb-button a').click(function(){
		if ($('#fb-content').is(':visible')) 
			$('#fb-content').animate({width: 'hide'});
		else
			$('#fb-content').animate({width: 'show'});
		return false;
	})	
	
	$('.bnr-slider').cycle({
		fx: 'fade',
		speed:  1000,
		timeout:  5000,
		random: 1
	});

	$('#newsletter input[type=text]').placeholder();
	
	$('#newsletter-send').click(function(){
		var email = $('#mail').val();
		$.get('./zapisz_do_newslettera.html?e=' + email, function(data) {
			$('#Newsleter-info').css('display','block');
			$('#Newsleter-info').html(data);
			});
		return false;
	})

	
});

