// url of extension
var baseExtUrl = 'typo3conf/ext/osfo_page/';
var current_page_id = null;

$(document).ready(function()
{
    $("#searchresults").click(function(){
        var searchresult = $("#form_search").attr("name");
        var param = $("#sword").val();
        var href = 'index.php?id='+searchresult+'&no_cache=1&sword='+param;
        window.location.href = href;
        return false;
    });
    
    current_page_id=$("#pageid").val();
    var buy = getURLParam("buy");

    $.getJSON(baseExtUrl+'remote.php',
        {'action':'getProductsInBasket','id':current_page_id, 'buy':buy},
        function(json){
        }   
    );
    
    $('.button-buy').click(function(){
        var pid = $(this).siblings(':hidden').val();
        var variant_id = $("#variant-"+pid).val();
        if ( variant_id == "undefined" ) {
            var variant_id = '';
        }
        var quantity = 1;
        $.getJSON(baseExtUrl+'remote.php',
            {'action':'buyProduct','id':current_page_id,'pid':pid,'variant_id':variant_id,'quantity':quantity},
            function(json){
            }
        );
    });
	
	// print page button
	$(".print > img").click(function(){window.print();return false;});
});

$(function(){
	$('ul.jd_menu').jdMenu();
	// tak toto nefunguje, takze to menim priamo v javascripte
	$('ul.jd_Menu').jdMenu({disableLinks:false});
	// Add menu hiding on document click
	$(document).bind('click', function() {
		$('ul.jd_menu ul:visible').jdMenuHide();
	});
	
	// correct the width of dropdown menus
	$("ul.mainmenu-second-level").each(function(i){
		var ow = $(this).width();
		$(this).css('width',ow);
	});
	//	$(this).css('min-width',ow);
	//	$(this).children("li").css('width','auto');
	//	$(this).children("li").css('min-width',ow + 8);
	//	//$(this).find("a").css('width',ow);
	//});

	// correct the width of dropdown menus for - IE bug
	//$("ul.mainmenu-second-level > li").each(function(i){
	//	var ow = $(this).parent().width();
	//	$(this).children("a").css('width',ow - 34);
	//});
	
	// if menu item has a submenu, add arrow icon
	$("ul.jd_menu > li > ul > li").each(function(i){
		if( $('ul',this).length > 0){
			$(this).addClass("hasSubmenu");
		}
	});
});

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 

function tx_dropdownsitemap_pi1_swapClasses( element )   {
        if( document.getElementById ) {
            var liClass                                  = "tx_dropdownsitemap_pi1_" + element;
            var picture                                  = "pic_" + element;
            document.getElementById( liClass ).className = ( document.getElementById( liClass ).className == "open" ) ? "closed" : "open";
            document.getElementById( picture ).src       = ( document.getElementById( liClass ).className == "open" ) ? "typo3conf/ext/dropdown_sitemap/res/folder-off.gif" : "typo3conf/ext/dropdown_sitemap/res/folder-on.gif";
        }
}
    
var tx_dropdownsitemap_pi1_expanded = 0;
function tx_dropdownsitemap_pi1_expAll()    {
    if( document.getElementsByTagName ) {
        var listItems = document.getElementsByTagName( "li" );
        for( i = 0; i < listItems.length; i++ ) {
            if( listItems[ i ].id.indexOf( "tx_dropdownsitemap_pi1" ) != -1 ) {
                listItems[ i ].className               = ( tx_dropdownsitemap_pi1_expanded ) ? "closed" : "open";
                    var picture                            = "pic_" + listItems[ i ].id.replace( "tx_dropdownsitemap_pi1_", "" );
                        listItems[ i ].className               = ( tx_dropdownsitemap_pi1_expanded ) ? "closed" : "open"
                        document.getElementById( picture ).src = ( tx_dropdownsitemap_pi1_expanded ) ? "typo3conf/ext/dropdown_sitemap/res/folder-on.gif" : "typo3conf/ext/dropdown_sitemap/res/folder-off.gif";
                    }
        }
    document.getElementById( "tx_dropdownsitemap_pi1_expImg" ).src = ( tx_dropdownsitemap_pi1_expanded == 1 ) ? "typo3conf/ext/dropdown_sitemap/res/exp-on.gif" : "typo3conf/ext/dropdown_sitemap/res/exp-off.gif"
    tx_dropdownsitemap_pi1_expanded                                = ( tx_dropdownsitemap_pi1_expanded == 1 ) ? 0 : 1;
    }
}
            