// preload rating imgs
var rating_imgs = new Array();

for(i=0; i<6; i++)
{
	rating_imgs[i] = new Image();
	rating_imgs[i].src = 'files/img/ratings/hearts'+i+'.gif';
}


function CenterMenu()
{
	var menu_width = parseInt($('#main_menu').width());
	
	$('#menu').width(menu_width);
	$('#menu').css('margin', '5px auto');
}

function ClearField(obj, is_focus)
{
	if(typeof(is_focus) == 'undefined')
		is_focus = true;
	
	if (($(obj).val() == '') || ($(obj).val() == $(obj).attr('defaultValue')))
	{
		if(is_focus)
			$(obj).val('');
		else
			$(obj).val($(obj).attr('defaultValue'));
	}
}


function SlideShow()
{
		var theInt = null;
		var $crosslink, $navthumb;
		var curclicked = 0;
		
		theInterval = function(cur){
			clearInterval(theInt);

			if( typeof cur != 'undefined' )
				curclicked = cur;
			
			$crosslink.removeClass("active-thumb");
			$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
			
			theInt = setInterval(function(){
				var img_count = $('.panelContainer div.panel').length;
				
				$crosslink.removeClass("active-thumb");
				$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( img_count == curclicked )
					curclicked = 0;
				
			}, 5000);
		};
		
		$(function(){
			
			$("#main-photo-slider").codaSlider();
			
			$navthumb = $(".nav-thumb");
			$crosslink = $(".cross-link");
			
			$navthumb
			.click(function() {
				var $this = $(this);
				theInterval($this.parent().attr('href').slice(1) - 1);
				return false;
			});
			
			theInterval();
		});
}

function checkAddEmailForm(f)
{
	if ( f.addemail.value == '' || f.addemail.value == 'Enter your email address' )
		return false;

	else if ( !f.addemail.value.match(/^[-a-zA-Z0-9_+.]+@[-a-zA-Z0-9.+]+\.[a-zA-Z]{2,}$/) )
	{
		alert('Email address format is incorrect...');
		return false;
	}
}

function OpenAlbum(file, width, height)
{
	var left = (screen.width/2)-(width/2);
	window.open('/albums'+file,'filewindow','top=50,left='+left+',scrolling=yes,width='+width+',height='+height+',scrollbars=yes,resizalbe=no');
}

function GetCalendar(field, date1, date2)
{
	var min_date, max_date;
	
	var d = new Date();

	//$.datepicker.setDefaults($.datepicker.regional['']);

	$('#'+field).datepicker();
	
	$('#'+field).datepicker('option', 'dateFormat', 'dd/mm/yy');
	$('#'+field).datepicker('option', 'firstDay', 1);
	$('#'+field).datepicker('option', 'changeMonth', true);
	$('#'+field).datepicker('option', 'changeYear', true);
	//$('#'+field).datepicker('option', 'yearRange', ''+(parseInt(d.getFullYear()) - 80)+':'+(parseInt(d.getFullYear()) + 5));
	
	if(typeof(date1) != 'undefined')
	{
		min_date = new Date(date1.substring(0, 4), date1.substring(5, 7)-1, date1.substring(8, 10));
		$('#'+field).datepicker('option', 'minDate', min_date);
	}
	
	if(typeof(date2) != 'undefined')
	{
		max_date = new Date(date2.substring(0, 4), date2.substring(5, 7)-1, date2.substring(8, 10));
		$('#'+field).datepicker('option', 'maxDate', max_date);
	}
}


function CreateVipRatingBar(id)
{
	var img = new Image();
		
	$(img).attr('src', 'files/img/ratings/hearts'+$('#stars'+id).val()+'.gif');
	$(img).attr('width', '75');
	$(img).attr('height', '16');
	$(img).attr('name', 'rate_bar'+id);
	$(img).attr('id', 'rate_bar'+id);
	$(img).attr('alt', 'Rate !');
	$(img).attr('title', 'Rate !');
		
	$(img).mousemove(function(e){
			var pos = $(this).offset();
			var x = parseInt((e.pageX-pos.left)/15)+1;
			
			$(this).attr('src', rating_imgs[x].src);
			
		});
		
	$(img).mouseout(function(e){
			$(this).attr('src', rating_imgs[parseInt($('#stars'+id).val())].src);
		});
		
	$(img).click(function(e) {
			var pos = $(this).offset();
			var x = parseInt((e.pageX-pos.left)/15)+1;
			
			$('#stars'+id).val(x);
			
		});
	
	$('#rating'+id).html($(img));
}


function html_to_polish(string)
{
	string = string.replace(/&#177;/, '¹');
	string = string.replace(/&#230;/, 'æ');
	string = string.replace(/&#234;/, 'ê');
	string = string.replace(/&#179;/, '³');
	string = string.replace(/&#241;/, 'ñ');
	string = string.replace(/&#243;/, 'ó');
	string = string.replace(/&#182;/, '¶');
	string = string.replace(/&#188;/, 'Ÿ');
	string = string.replace(/&#191;/, '¿');
	string = string.replace(/&#161;/, '¥');
	string = string.replace(/&#198;/, 'Æ');
	string = string.replace(/&#202;/, 'Ê');
	string = string.replace(/&#163;/, '£');
	string = string.replace(/&#209;/, 'Ñ');
	string = string.replace(/&#211;/, 'Ó');
	string = string.replace(/&#166;/, 'Œ');
	string = string.replace(/&#172;/, '');
	string = string.replace(/&#175;/, '¯');
	
	return(string);
}


function GetPlayerFile(file)
{
	return(GetURL()+'v/'+file.substring(file.length-6)+'/'+file.substring(0, file.length-6));
}


function GetPlayer(obj)
{
	/*
	var flashvars = {
		
		file: GetPlayerFile(obj)+'.flv',
		image: GetPlayerFile(obj)+'.jpg',
		autostart: 'true',
		backcolor: "000000",
		lightcolor: 'AAAAAA',
		frontcolor: 'CCCCCC',
		screencolor: '000000',
		controlbar: 'over',
		stretching: 'uniform',
	};
	
	var params = {
		quality: 'high',
		wmode: 'transparent',
		allowfullscreen: 'true',
		swliveconnect: 'true',
		scale: 'exactFit'
	};
	
	var attrs = {
		id: 'myContent1',
		name: 'myContent1'
	}

	swfobject.embedSWF(
		'/files/swf/media_player_4-4.swf',
		'flashcontent_myInSkin1',
		'500',
		'376',
		'8.0.0',
		'',
		flashvars,
		params,
		attrs
	);
	//*/
	
	$('#flashcontent_myInSkin1').flash({
		
		swf: '/files/swf/media_player.swf',
		params: {
			quality: 'high',
			wmode: 'transparent',
			allowfullscreen: 'true',
			swliveconnect: 'true',
			scale: 'exactFit'
		},
		
		flashvars: {
			file: GetPlayerFile(obj)+'.flv',
			image: GetPlayerFile(obj)+'.jpg',
			autostart: 'false',
			backcolor: "000000",
			lightcolor: 'AAAAAA',
			frontcolor: 'CCCCCC',
			screencolor: '000000',
			controlbar: 'over',
			stretching: 'uniform'
		},
		width: '500',
		height: '393',
		version: '8.0.0',
		attrs: {
			id: 'myContent1',
			name: 'myContent1'
		}
		
	});
	//*/
	
}

function VideoTabs(s)
{
	var per_page = 9;
	
	if(typeof(s) == 'undefined')
		s = '';
	
	// check if cookie exists
	var c_name = 'tabs' + s;
	var c_val = $.cookie(c_name);

	if(c_val == null)
	{
		c_val = '1;1';
		$.cookie(c_name, c_val, {path: '/', expires: 0});
	}
	
	c_val = c_val.split(';');

	var objs = $('#section_list a');
	
	for(var i=0; i<objs.length; i++)
	{
		if(i == c_val[0])
		{
			$(objs[i]).removeClass('tab_inactive');
			$(objs[i]).addClass('tab_active');
			
			$('#section_list_title').html($(objs[i]).html());
			
			GetVideoList(s, $(objs[i]).attr('href').substring(6), per_page, c_val[1]);
			
			$($(objs[i]).attr('href')).css('display', 'block');
		}
		else
			$($(objs[i]).attr('href')).css('display', 'none');
	}

	
	$('#section_list a').click(function() {

		var objs = $('#section_list a');

		for(var i=0; i<objs.length; i++)
		{
			if($(this).attr('href') == $(objs[i]).attr('href'))
			{
				$.cookie(c_name, c_val.join(';'), {path: '/', expires: '0'});
				
				$(this).removeClass('tab_inactive');
				$(this).addClass('tab_active');
				
				$('#section_list_title').html($(this).html());
				
				GetVideoList(s, $(this).attr('href').substring(6), per_page, 1);
				
				// show current div
				$($(this).attr('href')).css('display', 'block');
			}
			else
			{
				$(objs[i]).removeClass('tab_active');
				$(objs[i]).addClass('tab_inactive');
				$($(objs[i]).attr('href')).css('display', 'none');
			}
		}

		return false;
	});
}
