var host_name=""; 

var curbaseurl = document.location.protocol + '//' +
                 document.location.host +
                 ( document.location.port != '' ? ':' + document.location.port : '' ) +
                 '/';

function uistuff () {
	loading="<center><img style='margin-top:10%;' align='top' src='"+host_name+"fileadmin/templates/img/ajax-loader.gif' alt='loading' /></center>";
	
	basic_dialog = (function(){
		$("#dialog" ).dialog({			
			resizable: false,
			modal: true,
			width:290,
			height:'auto',
			autoOpen: false,
			title: "Online Boutique", 
			focus: function(){ 	$("#dialog").css('overflow','hidden');	}			
		});	
	});
	
	
	//OnlineBoutique Button
	/*$("#topnav li:nth-child(2)").click(function(){		
		basic_dialog();
		$("#topnav li:nth-child(2) a").attr("href","#");				
		$("#dialog").html(loading);
		$("#dialog").load(""+host_name+"fileadmin/develop/php/shopauswahl/shopauswahl.php", function(response, status, xhr) {
			  if (status == "error") {
				    var msg = "Sorry but there was an error: ";
				    console.log(msg + xhr.status + " " + xhr.statusText);
				    console.log(xhr);
				  }
				});

		$("#dialog").dialog('open');	
	});*/
	
	//Link in den eShop - direkt zum Look
	openDialogShopArtikel = (function(look){	
		basic_dialog();
		$("#dialog").html(loading);
		$("#dialog").load(""+host_name+"fileadmin/develop/php/shopauswahl/shopauswahl_land.php?look_neu="+look+"");
		$("#dialog").dialog('open');	
	});
	
	//Link in den eShop - Kategorieübersicht
	openDialogShopBasic = (function(look){
		basic_dialog();
		$("#dialog").html(loading);
		$("#dialog").load(""+host_name+"fileadmin/develop/php/shopauswahl/shopauswahl_land.php?essential="+look+"");
		$("#dialog").dialog('open');	
	});
	
	//Merkliste um Look erweitern
	update_produkt = (function(lookid) {
		basic_dialog();
		$("#dialog" ).dialog( "option", "width", 490 );
		$("#dialog" ).dialog( "option", "title", "Merkliste | Favourites" );
		$("#dialog").html(loading);
		$("#dialog").html("<iframe frameborder='0' width='470' height='550' src='"+host_name+"fileadmin/develop/php/merkliste/index.php?lookid="+lookid+"'></div>");
		$("#dialog").dialog('open');
		
	});
}

function fancyboxfunc () {
	//Fancybox 
	$("a[rel=lightbox]").fancybox({		
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	$(".csc-textpic-imagewrap a").fancybox({	
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$("input[type=submit]").addClass("tx-srfeuserregister-pi1-submit");
	
	//HR Bereich Empfänger Übergabe  
	var powermailto = getUrlVars()["to"];
	if(powermailto!=undefined){
		var action= $("#humanresources").attr("action");
		action_neu=action+"&to="+powermailto
		 $("#humanresources").attr("action",action_neu);
		}
	
	//My Wolford Bereich
	$(".btnMyWolford").click(function(){		
		basic_dialog();
		$("#dialog" ).dialog( "option", "title", "My Wolford" );		
		$("#dialog").html(loading);
		$("#dialog").load(""+host_name+"fileadmin/develop/php/shopauswahl/shopauswahl_crm.php");
		$("#dialog").dialog('open');	
	});
	
	$("#button").click(function(){
		targetUrl=$(this).attr("linkTo");
		window.open(targetUrl);
	});
	$('#button').bind('mouseenter mouseleave', function() {
		  $(this).toggleClass('button_hover');
	});
};

$(document).ready(function(){
	uistuff();

	if ( (typeof defer_fancybox === 'undefined') || (! defer_fancybox) ) {
		fancyboxfunc();
	}
});

//holt die get Parameter aus einer URL
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
//Slideshow
var stopSlideshow = false;
function slideSwitch() {
	if(stopSlideshow==false){
    var $active = $('#slideshow IMG.active');
    var $next =  $active.next().length ? $active.next()
            : $('#slideshow IMG:first');
    
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    
    if($next.hasClass("stop")){stopSlideshow=true;}
    
    

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
    }    
}
function CollectionOverview(){
	$('#slideshow IMG').removeClass('active');
	$('#slideshow IMG:last').addClass('active');	
	stopSlideshow=true;
	
}

function loadflashfile(filename){
	var flashfile = curbaseurl + 'fileadmin/kollektion/kollektionsdarstellung_neu/' + filename + '.swf';
	var flashobj  = '<object width="888" height="515" type="application/x-shockwave-flash" data="' + flashfile + '">' +
	            '    <param name="wmode" value="opaque" />' +
	            '    <param name="movie" value="' + flashfile + '">' +
	            ' </object>';
	var flashdiv = $("#flashContainer");
	flashdiv.css("background","#fff");
	flashdiv.css("width","888px");
	flashdiv.css("height","520px");
	flashdiv.html("<center><img src='"+host_name+"fileadmin/kollektion/kollektionsdarstellung_neu/ajax-loader.gif' style='margin-top:240px;' alt='loading' /></center>");
	flashdiv.html(flashobj);
}

$(function() {
	setInterval( "slideSwitch()", 3000 );
});

function openBigArtikel(bild){
	looknumber=bild.replace("LOOK ","");
	
	zusatz="";
	if(looknumber.length==1){zusatz="0";}
	
	image='"+host_name+"fileadmin/kollektion/kollektionsdarstellung_neu/bilder/big/look_'+zusatz+looknumber+'.jpg';	
	$.fancybox({		
		'titleShow' : false,
		'title': bild,
		'titlePosition' 		: 'inside',
		
		'href' : image		
		
		}); 
}

