// JavaScript Document

$(document).ready(function(){
	
    $('#lang').click(function() {
        $('#flags').slideToggle('fast');
    });

    // ABOUT US
    $('#knopAboutus').click(function() {
        $('#fade').fadeIn('fast');
        $('#aboutus').slideDown('fast');
        $(this).css({'z-index':'2','cursor' : 'default'});
    });
	
    // DISTRIBUTORS
    $('#knopDistributors').click(function() {
        $('#fade').fadeIn('fast');
        $('#distributors').slideDown('fast');
        $(this).css({'z-index':'3','cursor' : 'default'});
        $('.scroll-pane').jScrollPane();
		return false;
    });

    // WHERETOBUY
    $('#knopWheretobuy').click(function() {
        $('#fade').fadeIn('fast');
        $('#wheretobuy').slideDown('fast');
        $(this).css({'z-index':'3','cursor' : 'default'});
        $('.scroll-pane').jScrollPane();
    });


    // NEWSLETTER
    $('#knopNewsletter').click(function() {
        $('#fade').fadeIn('fast');
        $('#newsletter').slideDown('fast');
        $(this).css({'z-index':'2','cursor' : 'default'});
    });

    // CONTACT
    $('#knopContact').click(function() {
        $('#fade').fadeIn('fast');
        $('#contact').slideDown('fast');
        $(this).css({'z-index':'2','cursor' : 'default'});
    });

    // ROELER
    $('#knopRoeler').click(function() {
        /*$('#roeler').fadeIn('fast');
        $(this).css({'z-index':'2','cursor' : 'default'});
        $('#lang').fadeOut('slow');*/
        loadGallery('roeler');
    });

    // COLLECTION MEN
    $('#knopCollection-men').click(function() {
        loadGallery('men');
    });

    // COLLECTION WOMEN
    $('#knopCollection-women').click(function() {
        loadGallery('women');
    });

    // COLLECTION JUNIOR
    $('#knopCollection-junior').click(function() {
        loadGallery('junior');
    });

    // CLOSE
    $('#newsletter .close2, #distributors .close2, #wheretobuy .close2, #aboutus .close, #contact .close2, #collection-men .close, #fade').click(function() {
        $('#fade').fadeOut('fast', function(){
            $('.block').css({'z-index':'1','cursor' : 'pointer'});
            $('#newsletter, #distributors, #wheretobuy, #aboutus, #contact').slideUp('fast');
            $('#lang').fadeIn('slow');

            hideGallery('men');
            hideGallery('women');
            hideGallery('junior');
        });
    });
    // ZET ALLE Z-INDEX GOED BIJ STARTEN
    $('.block').css({'z-index':'1','cursor' : 'pointer'});

    // CLOSE Gallery
    $('#collection-men .close, #collection-women .close, #collection-junior, #collection-roeler .close').click(function() {
        $('#fade').fadeOut('fast', function(){
            $('.block').css({'z-index':'1','cursor' : 'pointer'});
            $('#collection-men, #collection-women, #collection-junior, #collection-roeler').fadeOut('fast');
            $('#lang').fadeIn('slow');
        });
    });

    // FORMULIER
    inputDefaultVal('input[title], textarea[title]');
	
	
	
	var a_pages = {
		'aboutus':'knopAboutus',
		'distributors':'knopDistributors',
		'collection_men':'knopCollection-men',
		'collection_women':'knopCollection-women',
		'collection_junior':'knopCollection-junior',
		'where_to_buy':'knopWheretobuy'
	};
	if(s_curPage != ''){
		$('#'+a_pages[s_curPage]).click();
	}
}); 

// GALLERY
//$(document).ready(function() {
function startSlideShow(){
    $(".slideshow").css("overflow", "hidden");
    $("ul.slides").cycle({
        fx: 'fade',
        pause: 1,
        prev: '.prev',
        next: '.next'
    });
    $(".slideshow").hover(function() {
        $("ul.nav").fadeIn();
    },
    function() {
        $("ul.nav").fadeOut();
    });
}
//});
function hideGallery(s_type){
    $('#collectionGallery_'+s_type).html('');
}
function loadGallery(s_type){
    $('#collectionGallery_'+s_type).html('');
    $.ajax({
        type: 'POST',
        url: s_siteUrl+"collection-"+s_type+".php?site_url="+s_siteUrl,
        success: function(s_html){
            $('#collectionGallery_'+s_type).html(s_html);
            startSlideShow();
			$('#collection-'+s_type).fadeIn('fast');
            $('#knopCollection-'+s_type).css({'z-index':'2','cursor' : 'default'});
            $('#lang').fadeOut('slow');
        },
        dataType: 'html'
    });
}


// MENU
var timeout    = 100;
var closetimer = 0;
var ddmenuitem = 0;
function jsddm_open(){
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}
function jsddm_close(){
    if(ddmenuitem){
        ddmenuitem.css('visibility', 'hidden');
    }
}
function jsddm_timer(){
    closetimer = window.setTimeout(jsddm_close, timeout);
}
function jsddm_canceltimer(){
    if(closetimer){
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
function jsddm_go(){
    jsddm_close();
    var i_clicked = $(this).attr('selId');
    var s_clicked = $(this).html();

    $('[name="selCur"]',$(this).parent().parent().parent()).html(s_clicked);

    $('#wheretobut_content').html('');
    $.ajax({
        type: 'POST',
        url: s_siteUrl+"wheretobut_content.php",
        data: {'pr':i_clicked},
        success: function(s_html){
            $('#wheretobut_content').html(s_html);
            $('.scroll-pane').jScrollPane();
        },
        dataType: 'html'
    });
}
$(document).ready(function(){
    $('#jsddm > li').bind('mouseover', jsddm_open);
    $('#jsddm > li').bind('mouseout',  jsddm_timer);
    //$('#jsddm > li a').bind('click',  jsddm_go);
	$('#jsddm li ul li a').bind('click',  jsddm_go);
});

//document.onclick = jsddm_close;


function inputDefaultVal(s_selector){
    $(s_selector).focus(function() {
        $(this).addClass("focus");
        if($(this).val() == $(this).attr('title')){
            $(this).val('');
        }
    }).blur(function() {
        $(this).removeClass("focus");
        $(this).val($(this).val() == '' ? $(this).attr('title') : $(this).val());
    });
}


function newsletterSendAjax(){
    var o_data = $("#newsletter_form").serialize();
    $('#newsletter_form_holder').html('');
    $.ajax({
        type: 'POST',
        url: s_siteUrl+"newsletter/index.php",
        data: o_data,
        success: function(s_html){
            $('#newsletter_form_holder').html(s_html);
            inputDefaultVal('input[title], textarea[title]','#newsletter_form_holder');
            change_captcha('newsletter_captcha');
        },
        dataType: 'html'
    });
}
function contactSendAjax(){
    var o_data = $("#contact_form").serialize();
    $('#contact_form_holder').html('');
    $.ajax({
        type: 'POST',
        url: s_siteUrl+"contact/index.php",
        data: o_data,
        success: function(s_html){
            $('#contact_form_holder').html(s_html);
            inputDefaultVal('input[title], textarea[title]','#contact_form_holder');
            change_captcha('contact_captcha');
        },
        dataType: 'html'
    });
}
function change_captcha(s_id){
    if($('#'+s_id+'_img').attr('id') != undefined){
        var src = $('#'+s_id+'_img').attr('src').split('?');
        $('#'+s_id+'_img').attr('src',src[0] + '?' + Math.random());
    }
}
