// This  js pluginn is made, because I got tierd of working whit non-working javascript frameworks like nyromodal and tickbox... This is how it is done whitout  bugs!
function priInitSet(){
	keyboardenabled = false;
	isItInterval = 0;
	slidePaused==0;
	////////// ("preinit");
	////jQuery("#masker").css("display", "none");
	jQuery("#pause_play").html("<img src='http://druzi.se/elements/cron_and_xml/img/play100.png'/>");
	jQuery("#pause_play").css("width", 25);
	jQuery("#pause_play").css("height", 25);
	jQuery("#pause_play").css("z-index", "161505");
	jQuery("#pause_play").stop().animate({ opacity: 0.7 }, 500);
	
	
	
	jQuery("#pause_play").css("display", "none");
	
	
	jQuery("#slide_counter").html("<p style='color:#FFFFFF;'><b>5</b></p>");
	jQuery("#slide_counter").css("display", "none");
	jQuery("#slide_counter").css("z-index", "161500");
	
	jQuery ("#theOneOf").css("position", "fixed");
	jQuery ("#theOneOf").css("z-index", "161000");
	jQuery ("#theOneOf").html("");
	jQuery ("#theOneOf").css("display","none");
	jQuery("#pauser_of_slide").css("z-index", "110000");
	var heigth_of_doc =(jQuery(window).height()-1);
	var width_of_doc =(jQuery(window).width()-1);
	////////////(jQuery("#masker").width());
	jQuery("#masker").css("width", width_of_doc);
	jQuery("#masker").css("height", heigth_of_doc);
	////////////(jQuery("#masker").width());
	jQuery("#pauser_of_slide").css("color", "#FFFFFF");
	jQuery("#pauser_of_slide").html("<p style='float:right;font-weight:bold;'><b>Slide Show Is OFF</b></p>");
	jQuery("#pauser_of_slide").css("display","none");
	jQuery("#pauser_of_slide").css("width",182);
	jQuery("#pauser_of_slide").css("height",21);
	jQuery("#pauser_of_slide").css("height",21);
	
	jQuery("#maskica").css("width", width_of_doc);
	jQuery("#maskica").css("height", heigth_of_doc);
	//jQuery("#maskica").css("display" "none");
	jQuery("#masker").css("display","none");
	
	jQuery("#Ftitle").css("display", "none");
	jQuery("#Ftitle").css("width", "auto");
	jQuery("#Ftitle").css("height", "auto");
	jQuery("#Ftitle").css("z-index", "100802");
	jQuery("#Ftitle").css("position", "fixed");
	
	jQuery("#mainloader").css("background-color", "#000");
	
	jQuery("#dispRight").html("<img src='http://druzi.se/elements/cron_and_xml/img/right.gif' style='cursor:pointer;'/>");
	jQuery("#dispLeft").html("<img src='http://druzi.se/elements/cron_and_xml/img/left.gif' style='cursor:pointer;'/>");
	jQuery("#dispRight").css('display', 'none');
	jQuery("#dispLeft").css('display', 'none');
	jQuery("#dispLeft").css('z-index', '100703');
	jQuery("#dispRight").css('z-index', '100702');
	jQuery("#dispLeft").css('position', 'fixed');
	jQuery("#dispRight").css('position', 'fixed');
	jQuery("#hotSpotLeft").css('display','none');
	jQuery("#hotSpotLeft").css('width','auto');
	jQuery("#hotSpotLeft").css('height','auto');
	jQuery("#hotSpotLeft").css('z-index','100800');
	jQuery("#hotSpotLeft").css('position','fixed');
	jQuery("#hotSpotLeft").css('border','none');
	jQuery("#hotSpotLeft").html("<img src='http://druzi.se/elements/cron_and_xml/img/hotspot.gif' id='leftspot' onclick='goLeft()' style='cursor: pointer;' />");
	
	
	jQuery("#hotSpotRight").css('display','none');
	jQuery("#hotSpotRight").css('width','auto');
	jQuery("#hotSpotRight").css('height','auto');
	jQuery("#hotSpotRight").css('z-index','100801');
	jQuery("#hotSpotRight").css('position','fixed');
	jQuery("#hotSpotRight").css('border','none');
	jQuery("#hotSpotRight").html("<img src='http://druzi.se/elements/cron_and_xml/img/hotspot.gif' id='rightspot' onclick='goRight()' style='cursor: pointer;' />");

	jQuery("#mainloader").css('position', 'fixed');
	jQuery("#closeButton").css('position', 'fixed');
	jQuery("#loadgif").css('position', 'fixed');
	jQuery("#closeButton").css("display","none");
	jQuery("#closeButton").html("<a href='javascript:priInitSet()'><img src='http://druzi.se/elements/cron_and_xml/img/close.jpg' title = 'Close'/></a> <br><hr> <a href ='javascript:getPartyUrl()'><img src = 'http://druzi.se/elements/cron_and_xml/img/GoToPartyIndex.jpg' title='Go To Party URL '/></a> <br><hr> <a href ='javascript:getPhoto()'><img src = 'http://druzi.se/elements/cron_and_xml/img/GoToThisPhoto.jpg' title='Get This'/></a> <br> <hr> <a href ='javascript:shareOnFacebook()'><img src = 'http://druzi.se/elements/cron_and_xml/img/InsertOnFacebook.jpg' title='Publish On Facebook'/></a><br> <hr> <a href ='javascript:copyPictureURL()'><img src = 'http://druzi.se/elements/cron_and_xml/img/CopyPictureURL.jpg' title='Copy URL'/></a> <br> <hr> <div id='slideDiv' style ='width:25px;height:25px;'><a href ='javascript:slide()'><img src = 'http://druzi.se/elements/cron_and_xml/img/startSlideshow.jpg' title='Slide Show'/></a></div>");
	jQuery("#loadgif").css("display",'none');
	jQuery("#loadgif").html("<img src = 'http://druzi.se/elements/cron_and_xml/img/ajaxLoader.gif' />");
	jQuery("#mainloader").css( 'z-index', '100700');
	jQuery("#closeButton").css('z-index', '100500')
	jQuery("#loadgif").css("z-index",'100501');
	initSet();
	
}
function  copyPictureURL(){
	//copy("Ovo je tekst za kopiranje");
	window.open("getText.php?text=" + escape(praviNiz[index]), "image url", "width=500,height=20");
}
function shareOnFacebook(){
	//document.location = "http://www.facebook.com/sharer.php?u=" + praviNiz[index];
	window.open("http://www.facebook.com/sharer.php?u="+ praviNiz[index],'share on facebook','width=500,height=800');
}
function getPhoto(){
	document.location = praviNiz[index];
}
function getPartyUrl(){
	 document.location = unescape(EventURL);
}

function handleArrowKeys(evt) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        switch (evt.keyCode) {
            case 37:
				if(keyboardenabled==true){
					goLeft();
				}
                break;    
           
            case 39:
				if(keyboardenabled==true){
					goRight();
				}
			
                break;    
            
         }
    }
}



function initSet(){
	
	//////////("init set");
	//jQuery("#masker").css("display", "none");
	jQuery("#pause_play").css("display", "none");
	jQuery("#slide_counter").css("display", "none");
	var heigth_of_doc =(jQuery(window).height()-1);
	var width_of_doc =(jQuery(window).width()-1);
	////////////(jQuery("#masker").width());
	jQuery("#masker").css("width", width_of_doc);
	jQuery("#masker").css("height", heigth_of_doc);
	
	jQuery("#mainloader").html("");
	jQuery("#mainloader").css( "display",'none');
	jQuery("#pauser_of_slide").css("display","none");
	jQuery("#hotSpotLeft").css('display','none');
	jQuery("#hotSpotRight").css('display','none');
	jQuery("#dispLeft").css('display', 'none');
	jQuery("#dispRight").css("display", "none");
	jQuery("#closeButton").css("display","none"); 
	jQuery("#loadgif").css("display",'none');
	jQuery("#Ftitle").css("display", "none");
	jQuery ("#theOneOf").css("display","none");
		
}
jQuery.noConflict();
jQuery(document).ready(function() {
	setTimeout(priInitSet,100);
	
	document.onkeyup = handleArrowKeys;
	
});
var countThis = 0;
var EventURL = ""; 
var isItInterval = 0;
var index=0;
var Primljeniniz = new Array();
var praviNiz = new Array();
var title = "";
var titleArray = new Array();
var openedFrom = ""
var slidePaused = 0;
var PrimljeninizTitla = new Array();
var videoEvents = new Array();
var keyboardenabled = false;

function procesVar(varijabla, titler, EvURL){
	////////////(varijabla);
		keyboardenabled = true;
		slidePaused=0;
		EventURL = EvURL;
		openedFrom = "pictureCowerflow";
		index=0;
		title = unescape(titler);
		//////(titler);
		//////(title);
		var str = varijabla;
		var total = praviNiz.length;
		for (a=0; a<total; a++){
			praviNiz.pop();
		}
		////////(praviNiz);
		Primljeniniz = null;
		Primljeniniz = str.split("||");
		////////(Primljeniniz);
		
		for(i=0; i<Primljeniniz.length; i++){
			praviNiz.push("http://druzi.se/data/partypics/" + Primljeniniz[i])
			if(i==Primljeniniz.length-1){
				//////////(praviNiz[index]);
			praviNiz.pop()
			openImage(escape(praviNiz[index]));	
			}
		}
}
function openEventPicture (fajl,identificator,titleOfFile,UrlOfNext){
	
/*	//ExternalInterface.call("openEventPicture", listersg,ID, titleString, EvURLs);
	EventURL = UrlOfNext;
	index = 0;
	praviNiz[index] = fajl;
	title = unescape(titleOfFile);
	openEventImage(escape("openImage.php?id=")+escape(fajl)); */
	
	
	
		openedFrom = "eventsCowerflow";
		index=identificator;
		//title = unescape(titler);
		//////(titler);
		//////(title);
		
		var total = praviNiz.length;
		for (a=0; a<1000; a++){
			praviNiz.pop();
			titleArray.pop();
			PrimljeninizTitla.pop();
			videoEvents.pop();
			if(a==999){
				var str = fajl;
			Primljeniniz = null;
			Primljeniniz = str.split(",");
			var str = unescape(titleOfFile);
			titleArray = str.split(",");
			var str = unescape(UrlOfNext);
			videoEvents = str.split(",");
			////////(Primljeniniz);
			
			for(i=0; i<Primljeniniz.length; i++){
				praviNiz.push(Primljeniniz[i]);
				if(i==Primljeniniz.length-1){
				
				title = titleArray[index];
				EventURL = videoEvents[index];
				//////////(praviNiz[index]);
	
				openImage(escape(praviNiz[index]));	
				
				}
			}
			
		}
	}
	
}

function slide(){
	jQuery("#slideDiv").html("<a href ='javascript:stopSlide()'><img src = 'http://druzi.se/elements/cron_and_xml/img/stopSlideshow.jpg' title='Stop Slide Show'/></a>");
	jQuery("#pauser_of_slide").html("<p style='float:right;font-weight:bold;'><b>Slide Show Is ON</b></p>");
	jQuery("#pause_play").html("<img src='http://druzi.se/elements/cron_and_xml/img/play100.png'/>");
	isItInterval = 1;
	slidePaused = 0;
	nextOneInTick ();

}

function nextOneInTick (){
	if(isItInterval==1 ){
		if(openedFrom == "pictureCowerflow"){
			// handler in case of openning from picture cowerflow
			
			if(slidePaused==0){
				if(isItInterval==1 ){
					if(index!=praviNiz.length-1){
						index++
						openImage(escape(praviNiz[index]));
					}else{
						isItInterval = 0;
					}
				}else{
					jQuery("#slideDiv").html("<a href ='javascript:slide()'><img src = 'http://druzi.se/elements/cron_and_xml/img/startSlideshow.jpg' title='Slide Show'/></a>");
				}
			}else{
				setTimeout(nextOneInTick,3000);
			}
		}else if(openedFrom == "videoCowerflow")
		{
		// handler in case of openning from video cowerflow - void
			
			
		}else if(openedFrom == "eventsCowerflow"){
			if(slidePaused==0){
				if(isItInterval==1 ){
					if(index!=praviNiz.length-1){
						index++
						openEventPicture (praviNiz.toString(),index,titleArray.toString(),videoEvents.toString())
					}else{
						isItInterval = 0;
					}
				}else{
					jQuery("#slideDiv").html("<a href ='javascript:slide()'><img src = 'http://druzi.se/elements/cron_and_xml/img/startSlideshow.jpg' title='Slide Show'/></a>");
				}
			}else{
				setTimeout(nextOneInTick,3000);
			}
		}
	}else{

	}
}
	
function stopSlide(){
	jQuery("#slideDiv").html("<a href ='javascript:slide()'><img src = 'http://druzi.se/elements/cron_and_xml/img/startSlideshow.jpg' title='Slide Show'/></a>");
	jQuery("#pauser_of_slide").html("<p style='float:right;font-weight:bold;'><b>Slide Show Is OFF</b></p>");
	isItInterval = 0;
	slidePaused = 0;
}
function countTo (){
	countThis--;
	//alert(countThis);
	
	if(countThis<=0 ){
	jQuery("#slide_counter").html("<p style='color:#FFFFFF;'><b> </b></p>");
	nextOneInTick();
	}else {
		jQuery("#slide_counter").html("<p style='color:#FFFFFF;'><b>"+countThis+"</b></p>");
		setTimeout(countTo ,1000);
	}
}

function openImage(imageUrl){
	keyboardenabled = true;
	initSet();
	//////////(imageUrl);
	

	var heigth_of_doc =(jQuery(window).height()-1);
	var width_of_doc =(jQuery(window).width()-1);


	//jQuery("#mainloader").css("display", "none");

	var prviy = (jQuery("#loadgif").height()/2);
	var kalkulacijay = (((jQuery(window).height()-1))/2) - prviy;
	var prvix = (jQuery("#loadgif").width()/2);
	var kalkulacijax = (((jQuery(window).width()-1))/2) - prvix;
	jQuery("#loadgif").css("top", kalkulacijay);
	jQuery("#loadgif").css("left", kalkulacijax);
	jQuery("#loadgif").css('display','block');
		
	jQuery("#mainloader").css("width",'auto');
	jQuery("#mainloader").css("height",'auto');
	jQuery("#masker").css("display", "block");

	jQuery('#mainloader').html("<img src='"+unescape(imageUrl)+"'  id='mainLoadedImage'/> ");

	setTimeout ( tempload, 1000 );
	function tempload (){
			setTimeout (safeLoad, 50 );
			//jQuery("#masker").css("display", "block");
	}
    function safeLoad(){
		
		jQuery("#loadgif").css("display", "none")
		
		jQuery("#mainloader").css( "z-index", '100501');
		
		var heigth_of_doc =(jQuery(window).height()-1);
		var width_of_doc =(jQuery(window).width()-1);
    	var Frameheight = jQuery("#mainloader").height();
		var FrameWidth = jQuery("#mainloader").width();
		if(Frameheight>50){
		
			if(Frameheight>heigth_of_doc){
				 
				 var eksHeight = Frameheight;
				 var eksWidth = FrameWidth;
				 var newProportion = Frameheight / (heigth_of_doc-50);
				 var Frameheight = eksHeight/newProportion;
				 var FrameWidth = eksWidth/newProportion;
			
				jQuery("#hotSpotLeft").css("width", FrameWidth/2);
				jQuery("#hotSpotLeft").css("height", Frameheight);
			
				jQuery("#mainloader").css("left", (width_of_doc - FrameWidth)/2 + "px");
				jQuery("#mainloader").css("top", (heigth_of_doc -Frameheight )/2 + "px");
				
				jQuery("#mainloader").css("width","auto");
				jQuery("#mainloader").css("height","auto");
				jQuery("#mainLoadedImage").css("height", Frameheight-1+"px");
				jQuery("#mainLoadedImage").css("width", FrameWidth-1 + "px");
				jQuery("#mainloader").css("height",Frameheight+ "px");
				jQuery("#mainloader").css("width",FrameWidth+ "px");
				jQuery("#mainloader").fadeIn('fast', function() {								  	
						 if(isItInterval == 1){
							
							countThis=6
							setTimeout(countTo,1000);
						 }
						  jQuery('#mainloader').focus();
				});
				
				jQuery("#mainloader").css("left", (width_of_doc - FrameWidth)/2 + "px");
				jQuery("#mainloader").css("top", (heigth_of_doc -Frameheight )/2 + "px");
								 
				jQuery("#leftspot").css("width", FrameWidth/2+ "px");
				jQuery("#leftspot").css("height", Frameheight + "px");
			
				jQuery("#rightspot").css("width", FrameWidth/2 + "px");
				jQuery("#rightspot").css("height", Frameheight + "px");
			
				
				//jQuery("#pauser_of_slide").css("top", ((width_of_doc - FrameWidth)/2) - (jQuery("#pauser_of_slide").width()/2) + "px");
				jQuery("#hotSpotLeft").css("left", (width_of_doc - FrameWidth)/2 + "px");
				jQuery("#hotSpotLeft").css("top", (heigth_of_doc -Frameheight )/2 + "px");
				jQuery("#hotSpotLeft").css('display','block');
				
				var constantW = ((width_of_doc - FrameWidth)/2);
				var constantH = (heigth_of_doc - Frameheight )/2;
			
				jQuery("#hotSpotRight").css("left", constantW + jQuery("#hotSpotLeft").width() + "px");
				jQuery("#hotSpotRight").css("top", constantH + "px");
				jQuery("#dispRight").css("left",  constantW + (jQuery("#hotSpotLeft").width()+ jQuery("#hotSpotRight").width())-jQuery("#dispRight").width() - 2 + "px");
				jQuery("#dispRight").css("top",  constantH + (jQuery("#hotSpotRight").height()/2)) +"px";
				//jQuery("#dispRight").css("display", "block");
				
				jQuery("#dispLeft").css('left', constantW + "px");
				jQuery("#dispLeft").css('top', constantH + (Frameheight/2) + "px");
				//jQuery("#dispLeft").css('display', 'block');
				
				jQuery("#hotSpotRight").css("display", "block");
			
			
				jQuery("#closeButton").css("width","auto");
				jQuery("#closeButton").css("height", "auto");
				jQuery("#closeButton").css("left",((width_of_doc - FrameWidth)/2)+ FrameWidth+ "px");
				jQuery("#closeButton").css("top", ((heigth_of_doc -Frameheight )/2)  +"px");
				jQuery("#closeButton").css('z-index', '100502');
				jQuery("#closeButton").css("display", "block");
				jQuery("#Ftitle").css("display", "block");
				jQuery("#Ftitle").html("<p><b>"+title+"</b></p>");
				jQuery("#Ftitle").css("top", ((heigth_of_doc -Frameheight )/2) - 25 +"px");
				jQuery("#Ftitle").css("left", (width_of_doc - FrameWidth)/2 + "px");
				
				jQuery ("#theOneOf").css("top", constantH + Frameheight + 5);
				jQuery ("#theOneOf").css("left", (width_of_doc - FrameWidth)/2);
				jQuery ("#theOneOf").html( "<p><b>" + (index+1) + "/" +(praviNiz.length) + "<b></p>");
				jQuery ("#theOneOf").css("display","block");
				
				jQuery("#pauser_of_slide").css("left", (width_of_doc/2) + (FrameWidth /2) - 182);
				jQuery("#pauser_of_slide").css("top", constantH + Frameheight + 5);
				jQuery("#pauser_of_slide").css("display","block");
				
				jQuery("#slide_counter").css("top", constantH + Frameheight + 5);
				jQuery("#slide_counter").css("left", (width_of_doc/2) - 5);
				
			
				if(isItInterval == 1){
					jQuery("#pause_play").css("left", constantW + 25)
					jQuery("#pause_play").css("top", constantH + Frameheight - 50);
					jQuery("#pause_play").css("display","block");
					jQuery("#slide_counter").css("display", "block");
				}
				
				
			}else{
			
		
			jQuery("#hotSpotLeft").css("width", FrameWidth/2);
				jQuery("#hotSpotLeft").css("height", Frameheight);
			
				jQuery("#mainloader").css("left", (width_of_doc - FrameWidth)/2 + "px");
				jQuery("#mainloader").css("top", (heigth_of_doc -Frameheight )/2 + "px");
				jQuery("#mainloader").css( "display",'none');
				//////////////("the case" + Frameheight)
				
				 //////////////("rekonfigured" +Frameheight )
				 
				jQuery("#mainloader").css("width","auto");
				jQuery("#mainloader").css("height","auto");
				jQuery("#mainLoadedImage").css("height", Frameheight-1+"px");
				jQuery("#mainLoadedImage").css("width", FrameWidth-1 + "px");
				jQuery("#mainloader").css("height",Frameheight+ "px");
				jQuery("#mainloader").css("width",FrameWidth+ "px");
				jQuery("#mainloader").fadeIn('slow', function() {								  	
						 if(isItInterval == 1){
							countThis=6
							setTimeout(countTo,1000);
						 }
						 jQuery('#mainloader').focus();
				});
				
				
				jQuery("#mainloader").css("left", (width_of_doc - FrameWidth)/2 + "px");
				jQuery("#mainloader").css("top", (heigth_of_doc -Frameheight )/2 + "px");
				
				
				 
				jQuery("#leftspot").css("width", FrameWidth/2+ "px");
				jQuery("#leftspot").css("height", Frameheight + "px");
				
				
			
				jQuery("#rightspot").css("width", FrameWidth/2 + "px");
				jQuery("#rightspot").css("height", Frameheight + "px");
			
			
			
				jQuery("#hotSpotLeft").css("left", (width_of_doc - FrameWidth)/2 + "px");
				jQuery("#hotSpotLeft").css("top", (heigth_of_doc -Frameheight )/2 +"px");
				jQuery("#hotSpotLeft").css('display','block');
				
				var constantW = ((width_of_doc - FrameWidth)/2);
				var constantH = (heigth_of_doc - Frameheight )/2;
				
					
				jQuery("#hotSpotRight").css("left", constantW + jQuery("#hotSpotLeft").width() + "px");
				jQuery("#hotSpotRight").css("top", constantH + "px");
				jQuery("#dispRight").css("left",  constantW + (jQuery("#hotSpotLeft").width()+ jQuery("#hotSpotRight").width())-jQuery("#dispRight").width()  + "px");
				jQuery("#dispRight").css("top",  constantH + (jQuery("#hotSpotRight").height()/2)) +"px";
				//jQuery("#dispRight").css("display", "block");
				
													
				
				jQuery("#dispLeft").css('left', constantW + "px");
				jQuery("#dispLeft").css('top', constantH + (Frameheight/2) + "px");
				//jQuery("#dispLeft").css('display', 'block');
				
				jQuery("#hotSpotRight").css("display", "block");
			
			
				jQuery("#closeButton").css("width","auto");
				jQuery("#closeButton").css("height", "auto");
				jQuery("#closeButton").css("left",((width_of_doc - FrameWidth)/2)+ FrameWidth + "px");
				jQuery("#closeButton").css("top", ((heigth_of_doc -Frameheight )/2) +"px");
				jQuery("#closeButton").css('z-index', '100502');
				jQuery("#closeButton").css("display", "block");
				jQuery("#Ftitle").css("display", "block");
				jQuery("#Ftitle").html("<p><b>"+title+"</b></p>");
				jQuery("#Ftitle").css("top", ((heigth_of_doc -Frameheight )/2)-40 +"px");
				jQuery("#Ftitle").css("left", (width_of_doc - FrameWidth)/2 + "px");
				
				jQuery ("#theOneOf").css("top", constantH + Frameheight + 5);
				jQuery ("#theOneOf").css("left", (width_of_doc - FrameWidth)/2);
				jQuery ("#theOneOf").html( "<p><b>" + (index+1) + "/" +(praviNiz.length) + "</b></p>");
				jQuery ("#theOneOf").css("display","block");
				
				jQuery("#pauser_of_slide").css("left", (width_of_doc/2) + (FrameWidth /2) - 182);
				jQuery("#pauser_of_slide").css("top", constantH + Frameheight + 5);
				jQuery("#pauser_of_slide").css("display","block");
				
				jQuery("#slide_counter").css("top", constantH + Frameheight + 5);
				jQuery("#slide_counter").css("left", (width_of_doc/2) - 5);
				
				
				
				if(isItInterval == 1){
					jQuery("#pause_play").css("left", constantW + 25)
					jQuery("#pause_play").css("top", constantH + Frameheight - 50);
					jQuery("#pause_play").css("display","block");
					jQuery("#slide_counter").css("display", "block");
				}
				
			}
		}else{
			safeLoad();
		}

	}
	//////////("no error");
}



function openIframe(url,videoId,Ftitle,PartyURL){
	keyboardenabled = true;
		slidePaused=0;
		openedFrom = "videoCowerflow";
		index=videoId;

		var str = url;
		
		var tit = unescape(Ftitle);
		var evURL = unescape(PartyURL);
		var total = praviNiz.length;
		for (a=0; a<total; a++)
		{
			praviNiz.pop();
			titleArray.pop();
			videoEvents.pop();
		}
		////////(praviNiz);
		Primljeniniz = null;
		Primljeniniz = str.split(",");
		PrimljeninizTitla = tit.split(",");
		videoEvents = evURL.split(",");
		(Primljeniniz);
		
		for(i=0; i<Primljeniniz.length; i++){
			praviNiz.push("http://www.youtube.com/v/"+Primljeniniz[i]+"?enablejsapi=1&playerapiid=ytplayer&fs=1&autoplay=1&showinfo=0&rel=0");
			titleArray .push(PrimljeninizTitla[i]) 
			if(i==Primljeniniz.length-1){
				//////////(praviNiz[index]);
			//praviNiz.pop()
			openVideoSlide(praviNiz[index],titleArray[index], videoEvents[index]);
			
			}
		}
	
}

function openVideoSlide (url,titleInArray,locationInArray){
	keyboardenabled = true;
	
	title = titleInArray;
	EventURL = locationInArray;
	
	//("opening video");
	//(url);
	//(Ftitle);
	var heigth_of_doc =(jQuery(window).height()-1);
	var width_of_doc =(jQuery(window).width()-1);
	
	var Frameheight = 385;
	var FrameWidth = 640;
	
	var prviy = (jQuery("#loadgif").height()/2);
	var kalkulacijay = (((jQuery(window).height()-1))/2) - prviy;
	var prvix = (jQuery("#loadgif").width()/2);
	var kalkulacijax = (((jQuery(window).width()-1))/2) - prvix;
	jQuery("#loadgif").css("top", kalkulacijay);
	jQuery("#loadgif").css("left", kalkulacijax);
	jQuery("#loadgif").css('display','block');
	
	jQuery("#mainloader").html("You need Flash player 8+ and JavaScript enabled to view this video. Get them, and stop waisting my time!");
	
	jQuery("#mainloader").css("width",640);
	jQuery("#mainloader").css("height",385);
	//http://www.youtube.com/v/
	//("so far so good")
	jQuery("#mainloader").css("left", (width_of_doc - FrameWidth)/2 + "px");
	jQuery("#mainloader").css("top", (heigth_of_doc -Frameheight )/2 + "px");
	
	//var svf =new SWFObject(url,"myytplayer", "100%", "100%", "10");
	/*var svf =new SWFObject("http://www.youtube.com/v/DJRUQLLwQ38?enablejsapi=1&playerapiid=ytplayer", "myytplayer", "100%", "100%", "10");
	svf.addParam("wmode","transparent");
	svf.addParam("allowfullscreen","true");
	svf.addParam("allowScriptAccess", "always");
	svf.addParam("id", "myytplayer");*/
	
	var svf =new SWFObject(url, "myytplayer", "100%", "100%", "10");
	svf.addParam("allowScriptAccess", "always");
	svf.addParam("wmode","transparent");
	svf.addParam("id", "myytplayer");
	svf.write("mainloader");
	jQuery('#mainloader').focus();
				
	//("every thing so far is good");
	jQuery("#closeButton").css("left",((width_of_doc - FrameWidth)/2)+ FrameWidth + "px");
	jQuery("#closeButton").css("top", ((heigth_of_doc - Frameheight )/2) +"px");
	jQuery("#Ftitle").html("<p>"+title+"</p>");
	jQuery("#Ftitle").css("top", ((heigth_of_doc/2) - Frameheight/2) - 35 +"px");
	jQuery("#Ftitle").css("left", (width_of_doc - FrameWidth)/2 + "px");
	jQuery("#closeButton").css('z-index', '111502');
	setTimeout(openMask,10);
	setTimeout(safeloadOfFrame, 1000);
	
	
	jQuery("#leftspot").css("width", FrameWidth/2+ "px");
	jQuery("#leftspot").css("height", Frameheight  - 110 + "px"); // set whit -110 so that youtube meny can be used
			
	jQuery("#rightspot").css("width", FrameWidth/2 + "px");
	jQuery("#rightspot").css("height", Frameheight - 110 + "px"); // set whit -110 so that youtube meny can be used
	
	jQuery("#hotSpotLeft").css("left", (width_of_doc - FrameWidth)/2 + "px");
	jQuery("#hotSpotLeft").css("top", (heigth_of_doc -Frameheight )/2 + "px");
	jQuery("#hotSpotLeft").css('display','block');
				
	var constantW = ((width_of_doc - FrameWidth)/2);
	var constantH = (heigth_of_doc - Frameheight )/2;
			
	jQuery("#hotSpotRight").css("left", constantW + jQuery("#hotSpotLeft").width() + "px");
	jQuery("#hotSpotRight").css("top", constantH + "px");
	jQuery("#dispRight").css("left",  constantW + (jQuery("#hotSpotLeft").width()+ jQuery("#hotSpotRight").width())-jQuery("#dispRight").width() - 2 + "px");
	jQuery("#dispRight").css("top",  constantH + (jQuery("#hotSpotRight").height()/2));
				//jQuery("#dispRight").css("display", "block");
				
	jQuery("#dispLeft").css('left', constantW + "px");
	jQuery("#dispLeft").css('top', constantH  + (jQuery("#hotSpotLeft").height()/2));
				//jQuery("#dispLeft").css('display', 'block');
				
	jQuery("#hotSpotRight").css("display", "block");
	
	jQuery ("#theOneOf").css("top", constantH + Frameheight);
	jQuery ("#theOneOf").css("left", (width_of_doc - FrameWidth)/2);
	jQuery ("#theOneOf").html( "<p><b>" + (index+1) + "/" +(praviNiz.length) + "</b></p>");
	jQuery ("#theOneOf").css("display","block");
	
	jQuery("#pauser_of_slide").css("left", (width_of_doc/2) + (FrameWidth /2) - 182);
	jQuery("#pauser_of_slide").css("top", constantH + Frameheight + 5);
	jQuery("#pauser_of_slide").css("display","block");
	
	////("no jscript error");
	
}

function onYouTubePlayerReady(playerId) {
      ("ready");
	  ytplayer = document.getElementById("myytplayer");
	  ytplayer.playVideo();
 	  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(state){
	if(isItInterval==1){
		if(state==0 & index!=praviNiz.length-1){
			index++
			openVideoSlide(praviNiz[index],titleArray[index], videoEvents[index]);
		}else if(state==0 & index==praviNiz.length-1){
			index=0;
			openVideoSlide(praviNiz[index],titleArray[index], videoEvents[index]);
		}
	}
}

function safeloadOfFrame(){
	jQuery("#masker").css("display", "block");
	jQuery("#loadgif").css('display','none');
	jQuery("#mainloader").css("display", "block");
	jQuery("#closeButton").css("display", "block");
	jQuery("#Ftitle").css("display","block");
}

jQuery(document).ready(function(){
	
jQuery("#pause_play").hover( 
	function (){
		jQuery("#pause_play").stop().animate({ opacity: 1.0 }, 500);
	},
	function(){
		jQuery("#pause_play").stop().animate({ opacity: 0.7 }, 500);
	});
	
jQuery("#closeButton").hover( 

	function (){
		pauseSlide();
	},
	function(){
		resumeSlide();
	});
								
								
	jQuery("#hotSpotLeft").hover( 

		function () {
										
			if(openedFrom == "pictureCowerflow" || openedFrom == "videoCowerflow" ||  openedFrom == "eventsCowerflow"){
				if(isItInterval==0 & index!=0){
						// ("over");
					jQuery("#dispLeft").css("display", "block");
					if(openedFrom != "videoCowerflow"){
						
					}
				}else if(isItInterval == 1){
					jQuery("#dispLeft").css("display", "none");
					if(openedFrom != "videoCowerflow"){
						
					}
					pauseSlide();
				}
			}
		},
		function ()
			{
			jQuery("#dispLeft").css("display", "none");
				if(isItInterval == 1)
				{
				resumeSlide();
				}
			}
		);
})
jQuery(document).ready(function(){
	jQuery("#hotSpotRight").hover( 
		function () {
			if(openedFrom == "pictureCowerflow" || openedFrom == "videoCowerflow" || openedFrom == "eventsCowerflow"){
					if(isItInterval==0 & index!= praviNiz.length-1){
						//("over right");
						jQuery("#dispRight").css("display", "block");
						
						
					}else if(isItInterval == 1){
						pauseSlide();
						jQuery("#dispLeft").css("display", "none");
						
					}
			}
		},
		function (){
			jQuery("#dispRight").css("display", "none");
				if(isItInterval == 1)
				{
				resumeSlide();
				}
			}
		
		);
});

function openMask(){
		jQuery("#masker").css("display", "block");
}

function pauseSlide (){
		if(openedFrom != "videoCowerflow" & isItInterval == 1){
		jQuery("#pause_play").html("<img src='http://druzi.se/elements/cron_and_xml/img/pause100.png'/>");
		jQuery("#pauser_of_slide").html("<p style='float:right;font-weight:bold;'><b>Slide Show Is Paused</b></p>");
		slidePaused = 1;
		}
}

function resumeSlide(){
	if(isItInterval == 1){
		slidePaused = 0;
		jQuery("#pauser_of_slide").html("<p style='float:right;font-weight:bold;'><b>Slide Show Is ON</b></p>");
		jQuery("#pause_play").html("<img src='http://druzi.se/elements/cron_and_xml/img/play100.png'/>");
	}
}

function goLeft(){
	if(slidePaused==0){
		if(isItInterval==1){
			stopSlide();
		}else{
			isItInterval = 0;
			jQuery("#hotSpotLeft").css('display','none');
			jQuery("#hotSpotRight").css('display','none');
			if(index!=0 & openedFrom == "pictureCowerflow" || index!=0 & openedFrom == "eventsCowerflow"){
					index--;
					openImage(escape(praviNiz[index]));
			}else if(index!=0 & openedFrom == "videoCowerflow"){
					index--;
					openVideoSlide(praviNiz[index],titleArray[index], videoEvents[index]);
					
			}else if(index!=0 & openedFrom == "eventsCowerflow"){
					index--;
					openEventPicture (praviNiz.toString(),index,titleArray.toString(),videoEvents.toString())
			}
		}
	}else{
		stopSlide();
	}
}
function goRight(){
	if(slidePaused==0){
		isItInterval = 0;
		jQuery("#hotSpotLeft").css('display','none');
		jQuery("#hotSpotRight").css('display','none');
		if(index!=praviNiz.length-1 & openedFrom == "pictureCowerflow"  ){
				index++;
				openImage(escape(praviNiz[index]));
		}else if(index!=praviNiz.length-1 & openedFrom == "videoCowerflow"){
				index++;
				openVideoSlide(praviNiz[index],titleArray[index], videoEvents[index]);
		}else if( index!=praviNiz.length-1 & openedFrom == "eventsCowerflow" ){
				index++;
				openEventPicture (praviNiz.toString(),index,titleArray.toString(),videoEvents.toString())
		}
	}else{
		stopSlide();
	}
}