// 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';
}
//*/

for(i=0; i<6; i++)
{
	rating_imgs[i] = new Image();
	rating_imgs[i].src = '/files/img/ratings/rating'+i+'.jpg';
}


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 IsPhoneToggle()
{
	if($('#contact_phone').is(':checked') && $('#share_phone').is(':checked'))
	{
		$('#is_phone').val('');
		$('#is_phone_text').text('Phone :');
	}
	else
	{
		$('#is_phone').val('1');
		$('#is_phone_text').text('Phone *:');
	}
}

function SetIsPhoneToggle()
{
	$('#contact_phone').click(function() {
		IsPhoneToggle();
	});
	
	$('#share_phone').click(function() {
		IsPhoneToggle();
	});
}


// rate to VIP Club
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 ToggleSchedule(obj)
{
	var id = $(obj).attr('id').substr(4);
	
	if($(obj).is(':checked'))
	{
		$('#stars'+id).val('0');
		GetSchedule(id);
	}
	else
		CreateVipRatingBar(id);
}

function PreloadRatings()
{
	jQuery.each($('table#rating_table tr'), function(i, val) {
		CreateVipRatingBar(parseInt($(val).attr('name').substr(3)));
		
	});
}


function ShowWindow(obj)
{
	if(typeof obj == 'string')
		obj = $(obj);
	
	$(obj).colorbox({
					transition:'fade',
					speed:500,
					opacity: 0.3,
					resize: false,
					iframe: false
					}
					
					);
}

function AdvertisementStep1()
{
	$('#check_code').click(function() {
		CheckPromoCode();
	});
	
	$('#select_all').click(function() {
		if($(this).is(':checked'))
			$('#select_all_label').html('<label for="select_all">Deselect all</label>');
		else
			$('#select_all_label').html('<label for="select_all">Select all</label>');
			
		$('input[name^="region"]').attr('checked', $(this).is(':checked'));
		
		CountTotalCost();
	});
	
	$('#nationwide').click(function() {
		
		jQuery.each($('input[name^="region"]'), function(i, val) {
			if(parseInt($(val).attr('id').substr(6)) < 10)
			{
				$(val).attr('checked', $('#nationwide').is(':checked'));
			}
		});
				
		CountTotalCost();
	});
	
	jQuery.each($('input[name^="region"]'), function(i, val) {
		
		$('#'+$(val).attr('id')).click(function() {
			CountTotalCost();
		});
	});
}

function CountTotalCost()
{
	var regions = new Array();
	
	var total_cost = 0;
	var cost = parseInt($('#cost').val());
	
	var all_regions = $('input[name^="region"]');
	var region_id;

	for(var i=0; i<all_regions.length; i++)
	{
		if($(all_regions[i]).is(':checked'))
		{
			total_cost += cost;
			
			region_id = parseInt($(all_regions[i]).attr('id').substr(6));
			
			if(region_id < 12)
				regions.push(region_id);
		}
	}
	
	if(total_cost > 0)
	{
		total_cost += parseInt($('#base_cost').val()) - cost;	
	}
	
	$('#total_cost').html(total_cost+' &pound;');
	
	$('#nationwide').attr('checked', (regions.length == 9 ? true : false));
}


function SetStepDirection()
{
	$('#step_prev').click(function() {
		$('#step').val('prev');
	});
	
	$('#step_next').click(function() {
		$('#step').val('next');
	});
}

function MultipleUploadFile(obj, type)
{
	var type_data = new Array();
	
	if(typeof(type) == 'undefined')
		type = 'image';
	
	switch(type)
	{
		case 'video':
			type_data['ext'] = 'avi|mov|mp4';
			type_data['max'] = 2;
			break;
			
		default:
			type_data['ext'] = 'jpg|jpeg|jpe|png';
			type_data['max'] = 4;
			break;
	}
	
	type_data['img'] = parseInt($('tbody#image_list').children('tr').length);
	
	$(obj).MultiFile({
		max: type_data['max'] - type_data['img'],
		accept: type_data['ext'],
		list: '#files_list'
		//STRING: {}
	});
	
}

function DeleteImgs()
{
	$('a.del_img').click(function(){
		
		var img_id = $(this).attr('id').substr(3);
		
		if(confirm('Do you really want to delete file \''+$(this).parent('td').prev().prev().text()+'\' ?'))
		{
			$('#to_del').val(img_id);
			$('#img_list_form').submit();
		}
		
		return(false);
		
	});
}

function DirectoryImgs()
{
	$('a.ad_picture_small').click(function(){
		
		var path_small = $(this).children('img').attr('src');
		var path_big = path_small.replace(/_m./, ".");
		
		$('#img_big').attr('src', path_big);

		return false;
	});
}

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',
		basedir: 'http://www.invideous.com/moderator/player/',
		plugins: 'invideousplug'
	};
	
	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',
		'100%',
		'100%',
		'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: '100%',
		//width: '100%'590,
		height: '100%',
		//height: '100%'444,
		version: '8.0.0',
		attrs: {
			id: 'myContent1',
			name: 'myContent1'
		}
		
	});
	//*/
	
	var InSkinParams = new Array();

	InSkinParams['srv_SectionID'] = '123763';
	InSkinParams['srv_SectionIDPlay'] = '123763';
	InSkinParams['srv_Keywords'] = '';
	InSkinParams['srv_Categories'] = '';
	InSkinParams['srv_UseSAS'] = 'false';
    InSkinParams['sas_PrerollAdTag'] = '';
    InSkinParams['sas_PauseAdTag'] = '';
    InSkinParams['sas_PlayAdTag'] = '';
    InSkinParams['plr_InSkinID'] = 'myInSkin1';
    InSkinParams['plr_ContentID'] = 'myContent1';
    InSkinParams['plr_ContentW'] = '500';
    InSkinParams['plr_ContentH'] = '393';
    InSkinParams['plr_FrameTop'] = '60';
    InSkinParams['plr_FrameSide'] = '45';
    InSkinParams['plr_FrameBottom'] = '40';
    InSkinParams['plr_InSkinW'] = '590';
    InSkinParams['plr_InSkinH'] = '493';
    InSkinParams['plr_TotalW'] = '900';
    InSkinParams['plr_TotalH'] = '600';
    InSkinParams['plr_ContentType'] = 'JWFLV';
    InSkinParams['plr_ExpandableDetached'] = 'true';
    InSkinParams['plr_NoSkinContentResize'] = 'true';
    InSkinParams['plr_NoSkinContentW'] = '590';
    InSkinParams['plr_NoSkinContentH'] = '464';
    InSkinParams['plr_NoSkinInSkinResize'] = 'true';
    InSkinParams['plr_NoSkinInSkinW'] = '590';
    InSkinParams['plr_NoSkinInSkinH'] = '464';
    InSkinParams['plr_AssumeSkin'] = 'false';
    InSkinParams['plr_InitOnLoad'] = 'true';
    InSkinParams['plr_InitAfterContent'] = 'true';
    
	InSkinLoad.init(InSkinParams);
	
	//$('#myContent1').attr('width', InSkinParams['plr_ContentW']);
	//$('#myContent1').attr('height', InSkinParams['plr_ContentH']);
	//*/
}


function GetHomePagePlayer(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',
		basedir: 'http://www.invideous.com/moderator/player/',
		plugins: 'invideousplug'
	};
	
	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',
		'home_page_player',
		'100%',
		'100%',
		'8.0.0',
		'',
		flashvars,
		params,
		attrs
	);
	
	var InSkinParams = new Array();

	InSkinParams['srv_SectionID'] = '123763';
	InSkinParams['srv_SectionIDPlay'] = '123763';
	InSkinParams['srv_Keywords'] = 'test';
	InSkinParams['srv_Categories'] = '';
	InSkinParams['srv_UseSAS'] = 'false';
    InSkinParams['sas_PrerollAdTag'] = '';
    InSkinParams['sas_PauseAdTag'] = '';
    InSkinParams['sas_PlayAdTag'] = '';
    InSkinParams['plr_InSkinID'] = 'myInSkin1';
    InSkinParams['plr_ContentID'] = 'myContent1';
    InSkinParams['plr_ContentW'] = '260';
    InSkinParams['plr_ContentH'] = '181';
    InSkinParams['plr_FrameTop'] = '40';
    InSkinParams['plr_FrameSide'] = '20';
    InSkinParams['plr_FrameBottom'] = '30';
    InSkinParams['plr_InSkinW'] = '300';
    InSkinParams['plr_InSkinH'] = '251';
    InSkinParams['plr_TotalW'] = '900';
    InSkinParams['plr_TotalH'] = '600';
    InSkinParams['plr_ContentType'] = 'JWFLV';
    InSkinParams['plr_ExpandableDetached'] = 'true';
    InSkinParams['plr_NoSkinContentResize'] = 'true';
    InSkinParams['plr_NoSkinContentW'] = '300';
    InSkinParams['plr_NoSkinContentH'] = '251';
    InSkinParams['plr_NoSkinInSkinResize'] = 'true';
    InSkinParams['plr_NoSkinInSkinW'] = '300';
    InSkinParams['plr_NoSkinInSkinH'] = '251';
    InSkinParams['plr_AssumeSkin'] = 'false';
    InSkinParams['plr_InitOnLoad'] = 'true';
    InSkinParams['plr_InitAfterContent'] = 'true';
    
	InSkinLoad.init(InSkinParams);
}


function ShowHideComments()
{
	var el = $('#comments').children();
	var height_sum = 0;
	var height_3 = 0;
		
	for(var i=0; i<el.length; i++)
	{		
		if(i < 3)
			height_3 += $(el[i]).height() + 8;
	}
	
	$('#comments').height(height_3);
	
	// action on click
	$('#comments_show_hide').click(function() {
		
		var el = $('#comments').children();
		var height_sum = 0;
		var height_3 = 0;
		
		for(var i=0; i<el.length; i++)
		{		
			height_sum += $(el[i]).height() + 8;
			
			if(i == 2)
				height_3 = height_sum;
		}
		
		if($('#comments').height() == height_sum)
			$('#comments').height(height_3);
		else
			$('#comments').height(height_sum);
		
		return false;
	
	});
}


function PageSectionTabs(s, subs)
{
	var per_page = 9;
	
	// check if cookie exists
	var c_name = 'tab-' + s + ((subs == '') ? '' : '-'+subs);
	var c_val = $.cookie(c_name);

	if(c_val == null)
	{
		c_val = '2;1';
		$.cookie(c_name, c_val, {path: '/', expires: 0});
	}
	
	c_val = c_val.split(';');
	// end cookie

	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());
			
			GetSectionList(s, subs, $(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());
				
				GetSectionList(s, subs, $(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;
	});
}


function ScrollSeries()
{
	$('ul.series_list a.link_grey_small').click(function() {
		$(this).parent().find('span').slideToggle('slow');
	});
	
	$('#series_container').jScroll();
}


function SearchResultHover()
{
	$('.search_result').mouseover(function() {
		$(this).addClass('search_hover');
	});
	
	$('.search_result').mouseout(function() {
		$(this).removeClass('search_hover');
	});
}

function Competition(logged)
{
	if(typeof(logged) == 'undefined')
		logged = 0;
	
	
}
