var Site = {

	equalizeProductCols: function() {

		// first iterate through all cols to find out which one is the largest
		jQuery('.prod2_table').each(function(){

			// define some vars
			var height = 0;
			var row = jQuery(this).parent().parent();

			// get tds
			jQuery('.wrapper_box',row).each(function(){if(jQuery(this).height()>height)height=jQuery(this).height();});

			// reset td height
			jQuery('.wrapper_box',this).css({height:height+'px'});

		});

		// do the same for our other cols
		var cols = jQuery('.oi-list-printers').length;
		var col = null;
		var row = null;
		if(cols) {

			// first col has always the most values
			var first_col = jQuery('.oi-list-printers').get(0);
			var row_i = 0;
			jQuery('li', jQuery(first_col)).each(function(){

				// define some vars
				var height = jQuery(this).height();

				// iterate through all remaining cols and check height
				for(var i = 1; i < cols; i++) {

					col = jQuery('.oi-list-printers').get(i);
					row = jQuery('li', jQuery(col)).get(row_i);
					if((row != undefined) && (jQuery(row).height() > height)) height=jQuery(row).height();

				}


				// iterate through all cols again and reset height
				for(var i = 0; i < cols; i++) {

					col = jQuery('.oi-list-printers').get(i);
					row = jQuery('li', jQuery(col)).get(row_i);
					jQuery(row).css({height:height+'px'});

				}

				// increment row
				row_i++;

			});

		}

	},

	toggleIntro: function(x) { jQuery('div.toggleIntro.'+x).slideToggle(500,function() { jQuery('a.toggle-button-'+x).html(jQuery(this).is(':visible')?SiteLNG.toggleIntroA:SiteLNG.toggleIntroB); }); },

        getProductFilter: function(data) {

            if(data['step'] == 2) {

                jQuery.get(
                    '/ajax.php',
                    {action:'get_product_filter',step:data['step'],language_id:data['language_id'],step1:jQuery('select[name="product_filter_step_1"]').attr('value')},
                    function(data) { jQuery('#product_filter_step_2').html(data['html']); },
                    'json'
                );

            } else if(data['step'] == 3) {

                jQuery.get(
                    '/ajax.php',
                    {action:'get_product_filter',step:data['step'],language_id:data['language_id'],step2:jQuery('select[name="product_filter_step_2"]').attr('value')},
                    function(data) {

                        if(data['url'] != undefined) window.location = data['url'];
                        else jQuery('#product_filter_step_3').html(data['html']);

                    },
                    'json'
                );

            } else if(data['step'] == 4) {

                window.location = jQuery('select[name="product_filter_step_3"]').attr('value');

            }

        }

}

// on document load
jQuery(document).ready(function() {

    // do we need to reset our scroll height?
    if(parseInt(jQuery('input[name="sc_set"]').attr('value')) > 0) jQuery(window).scrollTop(parseInt(jQuery('input[name="sc_set"]').attr('value')));
    else if(jQuery(window).height() < 800) {
	if(jQuery('table.layout-cart').length) jQuery(window).scrollTop(240);
	else if(jQuery('table.layout-products').length) jQuery(window).scrollTop(160);
	else if(jQuery('body.product-info').length) jQuery(window).scrollTop(240);

    } else if(jQuery('table#checkout-confirmation-top-button').length) {

	jQuery('table#checkout-confirmation-top-button').hide();

    }

    // when scroll event got triggered, set scroll height
    jQuery(window).scroll(function(){jQuery('input[name="sc"]').attr('value',jQuery(window).scrollTop());});
    jQuery('input[name="sc"]').attr('value',jQuery(window).scrollTop());

    // events for our dropdown_menu
    jQuery('td#menu_dropdown li.parent:last').addClass('l');
    jQuery('td#menu_dropdown li.parent').hover(
        function() {jQuery(this).addClass('s').find('ul:first').show();},
        function() {jQuery(this).removeClass('s').find('ul:first').hide();}
    );
    jQuery('td#menu_dropdown li.parent').each(function(){
        jQuery('ul li:last', this).addClass('l');
    });

    // fix table heights in product listing
    setTimeout('Site.equalizeProductCols()', 300);

    // event for oi-list-printers
    if(jQuery('ul.oi-list-printers').length) {

        jQuery('ul.oi-list-printers a').hover(
            function(){
                jQuery(this).parent().parent().parent().parent().parent().css({background:'#5B5B5B'}).find('a').css({color:'#FFF','text-decoration':'none'});
            },
            function(){
                jQuery(this).parent().parent().parent().parent().parent().css({background:'none'}).find('a').css({color:'#2F2F2F'});
            });

    }

    // zoom products
    if(jQuery('a.pzoom').length) {

	var offsetX = 20;
	var offsetY = 10;

	jQuery('a.pzoom').hover(function(e) {
	    var img = jQuery(this).attr('rel');
	    if(img.length) {

		jQuery('<img id="largeImage" src="'+img+'" alt="" border="0" />').css({top:e.pageY+offsetY,left:e.pageX+offsetX}).appendTo('body');

	    }

	}, function(){jQuery('#largeImage').remove();});

	jQuery('a.pzoom').mousemove(function(e){jQuery('#largeImage').css({top:e.pageY+offsetY,left:e.pageX+offsetX});});
	//jQuery('a.pzoom').click(function(e){e.preventDefault();});

    }

    // event for .sitemap
    if(jQuery('ul.sitemap').length) {

	var height = 0;
        jQuery('ul.sitemap').each(function(){if(jQuery(this).height() > height) height = jQuery(this).height();});
        jQuery('ul.sitemap').css({height:height+'px'});

    }

});

