
function showBox( defBox, defLink ) {
    defBoxes	= new Array();
    defBoxes[0]	= "Roofing";
    defBoxes[1]	= "Sheeting";
    defBoxes[2]	= "Sheeting2";
    defBoxes[3]	= "Paint";
    defBoxes[4]	= "Beton";
    defBoxes[5]	= "Transport";
    defBoxes[6]	= "Impregnation";
    for ( x = 0; x < 7; x++ ) {
        if ( defBox != "box"+defBoxes[x] ) {
            if ( document.getElementById('box'+defBoxes[x]) ) {
                document.getElementById('box'+defBoxes[x]).style.display	= "none";
            }
            if ( document.getElementById('link'+defBoxes[x]) ) {
                document.getElementById('link'+defBoxes[x]).style.display	= "inline-block";
            }
        }
    }
    if ( document.getElementById(defBox).style.display == "block" ) {
        document.getElementById(defBox).style.display	= "none";
        document.getElementById(defLink).style.display	= "inline-block";
    } else {
        document.getElementById(defBox).style.display	= "block";
        document.getElementById(defLink).style.display	= "none";
    }
}

function goTo( defURL ) {
    window.location( defURL );
    return false;
}



function sendContactForm()
{
    $('#bnwDD').val('checked');
    $data = $('#contactFormLeft').formSerialize();

    $.post('/sendForm.php', $data, function(msg){
        if (eval(msg) == 1) {
            $('#your_email').val('@');
            $('#your_phone').val('');
            $('#your_message').val("Sem můžete napsat svůj dotaz ...");
            alert("Zpráva byla úspěšně odeslána.");
        } else if (eval(msg) == 2) {
            alert("Odeslání zprávy se nezdařilo, zašlete nám prosím dotaz na email drevostavby@konrad.cz.");
        } else {
            alert("Vyplňte prosím e-mailovou adresu a text zprávy.");
        }
    })
    return false;
}


function countNoticeBoard()
{
    noticeBoard_width  = parseInt($('#noticeboard_width').val());
    noticeBoard_height = parseInt($('#noticeboard_height').val());
    noticeBoard_price  = parseFloat($('#noticeboard_price').val());
    if (noticeBoard_width > 0 && noticeBoard_height > 0) {
        getPrice = Math.ceil((noticeBoard_width + noticeBoard_height) * 2 * noticeBoard_price);
        $('#noticeboard_price_current').text(getPrice + ' CZK / 1 ks');
        $('#price_1_1').val(getPrice);
        $('#cart_product_noticeboard').val(noticeBoard_width + 'cm x ' + noticeBoard_height + 'cm');
        checkPrice();
    }
}

jQuery.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* @example value = $.getURLParam("paramName");
*/
 getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;

	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }

	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});

$(function() {
    $(".home-photo").jMyCarousel({
        visible: '660px',
        eltByElt: true,
        circular: true,
        auto: true,
        speed: 7000
    });
});

function msgBox(docID, imgFile)
{
    $('#questionPicture').html('<img src="/showPicturePreview.php?imgFile=' +  imgFile + '&imgWidth=250&imgHeight=190&imgCut=1" />');
    $('#bnwFile').val(imgFile);
    $('.msgForm').dialog({
        width: 450,
        title: 'Dotaz na výrobek',
        modal: true
    });
}

function sendMsgBox(docID, imgFile)
{
    $('#bnwDDD').val('checked');
    $data = $('#questionForm').formSerialize();

    $.post('/sendFormQuestion.php', $data, function(msg){
        if (eval(msg) == 1) {
            $('#gallery_your_email').val('@');
            $('#gallery_your_phone').val('');
            $('#gallery_your_message').val("Upřesněte požadovanou velikost dřevostavby (půdorys / výška), případně popište požadované odlišnosti od dřevostavby na fotografii:");
            $('.msgForm').dialog('destroy');
            alert("Zpráva byla úspěšně odeslána.");
        } else if (eval(msg) == 2) {
            alert("Odeslání zprávy se nezdařilo, zašlete nám prosím dotaz na email drevostavby@konrad.cz.");
        } else {
            alert("Vyplňte prosím e-mailovou adresu a text zprávy.");
        }
    })
    return false;
}

function sendMsgBox2(docID, imgFile)
{
    $('#bnwDDD').val('checked');
    //$data = $('#questionForm').formSerialize();

    return false;
}

function showResponse(responseText, statusText, xhr, $form)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
} 


    function slideSwitch(box) {
        var $active = $(box + ' img.active');
        if ( $active.length == 0 ) $active = $(box + ' img:last');
        var $next =  ($active.next().length == 1) ? $active.next() : $(box + ' img:first');
        $active.addClass('last-active');

        $next.hide()
            .addClass('active')
            .fadeIn('slow', function() {
                $active.removeClass('active last-active');
                $active.fadeOut('2000');
            });
    }


        function mycarousel_itemLoadCallback(carousel, state)
        {
            if (carousel.has(carousel.first, carousel.last)) {
                return;
            }

            jQuery.get(
                '/ajax-gallery.php',
                {
                    first: carousel.first,
                    last: carousel.last
                },
                function(xml) {
                    mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
                },
                'xml'
            );
        };

        function mycarousel_itemAddCallback(carousel, first, last, xml)
        {
            carousel.size(parseInt(jQuery('total', xml).text()));

            jQuery('image', xml).each(function(i) {
                carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
            });
        };

        function mycarousel_getItemHTML(itemInfo)
        {
            itemInfo = itemInfo.split('|');
            return '<a href="' + itemInfo[2] + '"><img src="' + itemInfo[0] + '" width="112" height="79" alt="" /></a><br /><span>' + itemInfo[1] + '</span>';
        };



$(document).ready(function() {
    $('.expand').expander({
        slicePoint: 750,
        expandText: '[čtěte více]',
        userCollapseText: '[čtěte méně]'
    });
    $(".lightbox").lightBox({fixedNavigation:true});
    $("a[rel*='lightbox']").lightBox({fixedNavigation:true});
    $('.msgForm').bind( 'dialogclose', function() {
        $('.msgForm').dialog('destroy');
    });
    $('.box-gallery').jcarousel({
        itemLoadCallback: mycarousel_itemLoadCallback,
        wrap: 'circular',
        scroll: 7,
        auto: 6
    });
    setInterval( "slideSwitch('.pageHeaderPicture')", 5000 );
    $('#questionForm').ajaxForm({
        //success:  showResponse
        success: function (msg){
            if (eval(msg) == 1) {
                /*$('#gallery_your_email').val('@');
                $('#gallery_your_phone').val('');
                $('#gallery_your_message').val("Upřesněte požadovanou velikost dřevostavby (půdorys / výška), případně popište požadované odlišnosti od dřevostavby na fotografii:");*/
                $('#questionForm').resetForm();
                $('.msgForm').dialog('destroy');
                alert("Zpráva byla úspěšně odeslána.");
            } else if (eval(msg) == 2) {
                alert("Odeslání zprávy se nezdařilo, zašlete nám prosím dotaz na email drevostavby@konrad.cz.");
            } else {
                alert("Vyplňte prosím e-mailovou adresu a text zprávy.");
            }
        }
    });
});


