var modded = false;
var xp_new_window_class = "new-window";
var wWith = "800";
var wHeight = "600";
var windowName = 'aWindow';
var windowOptions = 'resizable=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes';
var pos = 0;
var height = 0;

var fader = null;

$(window).load(function(){
	$('div.preload').hide();
	$('div.fader').show();
	$('div.gallery-wrapper').show();
	fader = $('div.fader').cycle({timeout:7500,speed:2500});
	positioning();
	try{
		$('div.main-col div.col-padding').jScrollPane({showArrows:true, scrollbarWidth:10});	
	}
	catch(e){
		
	}
	
	try{
		$('div.products-col div.col-padding').jScrollPane({showArrows:true, scrollbarWidth:10});	
	}
	catch(e){
		
	}
	$('a.new-window').click(function(){
        var url = $(this).attr('href');
        if (url) newWindowWithURL(url);
        return false;
    });
	$('#main-menu ul').width();
	
	
	
});

var galleryToActivate = null;

$(document).ready(function(){
		/*$('#product-menu a').click(function(){
        	var url = $(this).attr('href');
        	if (url) 
            	newWindowWithURL(url);
        	return false;
			/*$('div.fader').cycle('stop');*/
		/*});*/
		//$('ul.sf-menu').superfish({autoArrows:false});
		
		
		$('div#footer div.menu ul li a span.icon-wrapper').each(function(){
				var newElement = $(this).clone();
				$(this).parent().append(newElement);
				$(this).remove();
			
		});
		
		$('.pictures a.fancybox').fancybox({
			padding:"50"
		});
		
        
	
});



function enableMenu(elementID, updateAnchor){
	

	
	if(updateAnchor==null) updateAnchor = false;
    $('.active-photo-gallery').hide();
    $('.active-photo-gallery').stop();
    $('#product-menu a.selected').removeClass('selected');
    if(updateAnchor)
		 $('a[rel='+elementID+']').addClass('selected');
    
    $('.active-menu').slideToggle('slow');
    $('.active-menu').removeClass('active-menu');
    
    $('#' + elementID + ' .product-col-spacer').slideToggle('slow');
    $('#' + elementID + ' .product-col-spacer').addClass('active-menu');
    
	
	if (!$.support.style) {
		$('#' + elementID + ' .product-col').css({
			filter:'progid:DXImageTransform.Microsoft.gradient(startColorstr=#b3ffffff, endColorstr=#b3ffffff)'
		});
	}
    //Slide show
    
    
    galleryToActivate = '#' + elementID + '-photo-gallery';
    setTimeout("activateGallery('" + galleryToActivate + "')", 750);
    $(galleryToActivate).cycle();
    $(galleryToActivate).addClass('active-photo-gallery');
}

function activateGallery(gal){
	$(gal).fadeIn();
}

$(window).resize(function(){
	positioning();
});
$(window).scroll(function(){
	positioning();
});

function positioning(){
	if(!$.support.style){
    	$('#product-intro').css({
    		position:'absolute',
    		top : $('.gallery-wrapper').offset().top, 
    		left: $('.gallery-wrapper').offset().left+9,
    		zIndex:1000/*,
    		filter:'progid:DXImageTransform.Microsoft.gradient(startColorstr=#b3ffffff, endColorstr=#b3ffffff)'*/
    	});
	}
	else{
		$('#product-intro').css({
    		position:'absolute',
    		top : $('.gallery-wrapper').offset().top, 
    		left: $('.gallery-wrapper').offset().left+9,
    		zIndex:1000/*,
    		background:'rgba(255,255,255,0.7)'*/
    	});
	}
    	
    $('#product-intro').show();
}

function newWindowWithURL(anHref){
    var queryString = anHref.replace(/^[^\?]+\??/, '');
    var params = xp_parseQuery(queryString);
    if (params['width'] != null && params['width'] != '') 
        wWith = params['width'];
    if (params['height'] != null && params['height'] != '') 
        wHeight = params['height'];
    if (anHref != null && anHref != '' && anHref != '#') {
        //$('input, textarea, select').attr('disabled','true');
        var newWindow = window.open(anHref, windowName, windowOptions + ',width=' + wWith + ',height=' + wHeight);
        newWindow.focus();
    }
}

function xp_parseQuery(query){
    var Params = {};
    if (!query) {
        return Params;
    }// return empty object
    var Pairs = query.split(/[;&]/);
    for (var i = 0; i < Pairs.length; i++) {
        var KeyVal = Pairs[i].split('=');
        if (!KeyVal || KeyVal.length != 2) {
            continue;
        }
        var key = unescape(KeyVal[0]);
        var val = unescape(KeyVal[1]);
        val = val.replace(/\+/g, ' ');
        Params[key] = val;
    }
    return Params;
}
