﻿function LoadAdditionalRightbarSlides() {
	$.get('/includes/RightbannerFirstpage.ashx?strIDs=' + strArkIDs, function (response) {
		var intCount = $(response).length;
		intMaxIndex = intMaxIndex + intCount;
		$('.galleryarea ul').append(response);
		//		var ulCounter = $('ul.counter');
		//		for (var i = 0; i < intCount; i++) {
		//			ulCounter.append('<li><a href=""#""></a></li>');
		//		}
	}, 'html');
}
$(document).ready(function () {
	$('ul.counter').remove();
	$('.gallery').append('<ul class="switcher"><li class="left"><a href="#"></a></li><li class="right"><a href="#"></a></li></ul>');
	$('ul.switcher li').click(function () {
		var tmpIndex; //= intCurrentIndex;
		if ($(this).hasClass('left')) {
			tmpIndex = intCurrentIndex - 1;
		}
		else {
			tmpIndex = intCurrentIndex + 1;
		}
		SwitchImage(tmpIndex);
		return false;
	});
	setTimeout(LoadAdditionalRightbarSlides, 2000);
	$('a[data-film]').click(function () {
		shadowBox($(this).attr('data-film'));
		return false;
	});
});


function GetCenterValuesHoriz(intDialogWidth) { //Returns the value position left depending on the width of window
	var windowWidth = $(window).width();
	var popupWidth = intDialogWidth;
	return (windowWidth / 2 - popupWidth / 2);
}
function GetCenterValuesVertic(intDialogHeight) { //Returns the value position top depending on the height of window
	var windowHeight = $(window).height();
	var popupHeight = intDialogHeight;
	return (windowHeight / 2 - popupHeight / 2);
}

function shadowBox(data) {
	//Show shadowbox
	//$('#gallery li').click(function () {
	//data = $(this).attr('data-film');
	if (!data) {
		return false;
	}
	//clearInterval(oInterval);
	//runAutoSwitch = false;
//	$('#shadowWrapper').css({
//		'display': 'block'
	//	});
	$('#shadowWrapper').show('500');
	
	//id = $(this).children('img').attr('data-filmId');
	$.get('/includes/getFilmHTML.ashx', { filmid: data }, function (data) {
		$('#video .filmen').html(data);
		$('#videoWrapper').css({
			'display': 'block',
			'top': GetCenterValuesVertic($('#videoWrapper').height()),
			'left': GetCenterValuesHoriz($('#videoWrapper').width())
		});
	});
	//}
	//});

	//Closeshadowbox
	$('#shadow').click(function () {
		//runAutoSwitch = true;
		//oInterval = setInterval(AutoSwitcher, 5000);
		$('.galleryarea').css({ 'border': '3px solid #ffffff' });
		$('#shadowWrapper').hide('500'); //.css({ 'display': 'none' });
		$("#video .filmen").html('');
	});
    $('#close').click(function () {
        //runAutoSwitch = true;
        //oInterval = setInterval(AutoSwitcher, 5000);
        $('.galleryarea').css({ 'border': '3px solid #ffffff' });
        $('#shadowWrapper').hide('500'); //.css({ 'display': 'none' });
        $("#video .filmen").html('');
    });
	//Centerar videobox
	$(window).resize(function () {
	    $("#videoWrapper").css({
			"top": GetCenterValuesVertic($("#video").height()),
			"left": GetCenterValuesHoriz($("#video").width())
		});
	});
}
