var media_window_status = 0;
	
$("document").ready(function(){
	
	var myInterval = window.setInterval('header_dynamic()',7000);
	//window.setTimeout(window.clearInterval(myInterval),3500);
	/*while(){	
	window.setTimeout('header_dynamic()','1000');
	}*/
	
	$().keyup(function(event){
    if (event.keyCode == 27) {
		media_window_close();
    }
    if (event.keyCode == 39) {
		media_window_next();
    }
    if (event.keyCode == 37) {
		media_window_prev();
    }
    if (event.keyCode == 38) {		
		//media_window_typeup();
    }
    if (event.keyCode == 40) {
		//media_window_typedown();
    }
	});
	
	$('#media_window_frame').click(function () { 
		//media_window_close();
    });	
	
	$('#media_window').click(function () { 
		media_window_next();
    });	
	
	$('.thumb.video').click(function () { 
		url = $(this).attr('url'); 
		href='youtube.php?url=' + url + '&action=this';
		$('#media_window').load(href);
		$('#media_window_frame').fadeIn();
		$('#media_window').fadeIn();
		media_window_status = 2;
    });	
	
	$('.thumb.photo').click(function () { 
		url = $(this).attr('url'); 
		href='img.php?url=' + url + '&action=this';
		$('#media_window').load(href);
		$('#media_window_frame').fadeIn();
		$('#media_window').fadeIn();
		media_window_status = 1;
    });
	
	//REMOVE DEFAULT VALUE FROM INPUT FIELDS OF TYPES TEXT AND PASSWORD

	$('input[type=text],input[type=password]').focus(function(){
		this.value == this.defaultValue ? this.value='' : '';
	})
	.blur(function(){
		this.value == '' ? this.value = this.defaultValue : '';
	});

	//EFFECTS FOR PROFILE IMAGE AT EXTRA BOX
	
	$("div.extra").hover(function () {
		$('#profile_img').fadeIn('fast');
	},
	function () {
		$('#profile_img').fadeOut('normal');
	});
	
	//FADING EFFECT FOR THE MINI MENU INSIDE THE SLIDER

	$(".slider_action").hover(function () {
		$(this).stop().animate({
			opacity: 0.8
		}, 'slow');
	},
	function () {
		$(this).stop().animate({
			opacity: 0.4
		}, 'slow');
	});

});

	
function media_window_close(){
	$('#media_window_frame').fadeOut();
	$('#media_window').html('');
	media_window_status = 0;
}

function media_window_next(){
	//alert('nęste');
	if(media_window_status==2){
		href='youtube.php?url=empty&action=next';
		$('#media_window').load(href);
	}	
	if(media_window_status==1){
		href='img.php?url=empty&action=next';
		$('#media_window').load(href);
	}
}

function media_window_prev(){
	//alert('nęste');
	if(media_window_status==2){
		href='youtube.php?url=empty&action=prev';
		$('#media_window').load(href);
	}	
	if(media_window_status==1){
		href='img.php?url=empty&action=prev';
		$('#media_window').load(href);
	}
}

function media_window_typeup(){
	if(media_window_status > 0){
		media_window_status--;
		media_window_prev()
	}
}

function media_window_typedown(){
	if(media_window_status > 0 && media_window_status < 2){
		media_window_status++;
		media_window_prev()
	}
}

function header_dynamic(){	
	//alert();
	$('#header_dynamic').fadeOut(function(){
		$('#header_dynamic').load('header.php', function(){
			$('#header_dynamic').fadeIn();
		});
	});
	
	
}

//SLIDER CONTROLLER

//	waiting variable for sliding animation
var wait = 0;

function slider(action, click_object){
	//	check if the sliding animations i done
	if(wait == 0){
		//$(click_object.parentNode.).parents("div.sliderframe div.slider_inner").slideUp();
		
		//	intiate the slider_inner object
		slider_inner = $(click_object.parentNode.parentNode).children('div.slider_frame').children('div.slider_inner');
		
		//	gets the width of the objects inside
		slider_width = $(click_object.parentNode.parentNode).children('div.slider_frame').width();
		
		//counts the number of div's inside the slider_inner object (the images)
		imgcount = slider_inner.children().length;
		
		//the current Margin_Left is calculated
		Margin_Left = slider_inner.css('marginLeft');
		sub = Margin_Left.length-2;
		Margin_Left = Margin_Left.substr(0,sub);

		if(action == "next"){
			wait = 1;
			if(Margin_Left > -((imgcount-1)*slider_width)){
				slider_inner.animate({marginLeft : '-=' + slider_width + 'px'}, 'slow', function () {wait=0;});
			}
			else{
				slider_inner.animate({marginLeft : '0px'}, 'slow', function () {wait=0;});
			}
		}
		
		if(action == "prev"){
			wait = 1;
			if(Margin_Left < 0){
				slider_inner.animate({marginLeft : '+=' + slider_width + 'px'}, 'slow', function () {wait=0;});
			}
			else{
				wait=0;
			}
		}
	}
}

