$(document).ready(function() {
	setCatCarasoul();	
	$('input[title!=""]').hint();		//activate form hints
	swf_flashinstructions();			//flash banner
});

function setCatCarasoul() {

   //default values
   cc_startPosition = 0;
   cc_activePosition = cc_startPosition;
   cc_size = $('.carasoul .videochannels').children().size();
   cc_visible = 4;

   //find active state
   count = 0;
	$('.carasoul .videochannels li').each( function() {
		if (this.className == 'active') { 
			cc_activePosition = count
		}
		count++;		
    });
	
	//determine start position
	if ( (cc_size-cc_activePosition) <  cc_visible) { 
		cc_startPosition = cc_size - cc_visible; 
	}
	
	//set next/previous
	if (cc_activePosition == 0) { $(".prv").addClass('disabled'); }
	if ((cc_activePosition + 1) == cc_size) { $(".nxt").addClass('disabled'); }
	$(".nxt").click( function () { return false;  } );
	$(".prv").click( function () { return false;  } );
	
	//setup JcarasoulLite
	$(function() {
	    $(".carasoul").jCarouselLite({
			circular: false,
	        btnNext: ".nxt",
	        btnPrev: ".prv",
			start: cc_startPosition,
			visible: cc_visible
	    });
	});
}


function setVideo(htmlId, dmobject, videoUrl) {
	
    var params = { 
		allowScriptAccess: "always",
		autoplay: 1,
		wmode: 'transparent'
	};
    var atts = {  };
    swfobject.embedSWF(videoUrl+'&enablejsapi=1&rel=0', htmlId, "363", "300", "8", null, null, params, atts);
	
	if (dmobject) {
		document.getElementById('mainvideo_desc').innerHTML = dmobject.getElementsByTagName('pre')[0].innerHTML; 
		document.getElementById('mainvideo').getElementsByTagName('h3')[0].innerHTML = dmobject.getElementsByTagName('div')[0].innerHTML; 
		document.getElementById('mainvideo_misc').getElementsByTagName('input')[0].value = dmobject.getElementsByTagName('a')[0].href;
		document.getElementById('mainvideo_misc').getElementsByTagName('input')[1].value = ytEmbedCode(videoUrl);
		document.getElementById('mainvideo_flag').href = dmobject.getElementsByTagName('div')[1].innerHTML;
		document.getElementById('mainvideo_misc').style.display = 'block';
		document.getElementById('mainvideo_date').innerHTML = dmobject.getElementsByTagName('strong')[0].innerHTML; 
	}
	
}

function ytEmbedCode(videoUrl) {
	var misccontent = '<object width="425" height="344"><param name="movie" value="'+videoUrl+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+videoUrl+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
	return misccontent;
}

function tbclose() {
	self.parent.tb_remove();
}


/* sky news */
function swf_flashinstructions() {
    var params = { 
		allowScriptAccess: "always",
		autoplay: 1,
		bgcolor: '#FFFFFF',
		quality: 'high',
		wmode: 'transparent'
	};
    var atts = {  };
    swfobject.embedSWF(
		'/inc/flash/skynews_vide3_7.swf?url1=/site-skynews/article/index/faq.html&url2=/site-skynews/video_upload.html&url3=/site-skynews/&url4=/site-skynews/article/index/faq.html&url5=/site-skynews/article/index/termsconditions.html&url6=/site-skynews/video_upload.html', 
		'flash_details', 
		"226", 
		"373", 
		"8", 
		null, 
		null, 
		params, 
		atts);
}

function ajaxVideoMenu() {
	$.get("/site-skynews/home.html", function(data){
		$("#videomenu").html(
			$("#videomenu", data).html()
		);
		setCatCarasoul();
		$("#videomenu").removeClass("preloader");
	});
}

function hitboxtrigger_pageviews(a) {
	try {
		_hbPageView(a,hbx.mlc);
	} catch(err) { }
}