var map;
var geocoder;
var map_created = false;
var map_zoom = 11;
var map_top = -179;
var map_bottom = -1;
var map_left = 179;
var map_right = 1;
var video_host = 'http://cdn.platinumhd.tv';

function play_flash(divId){
	flowplayer(divId , {src: 'assets/flash/flowplayer-3.1.1.swf', wmode: 'transparent' }, {
		clip: {
			autoPlay: false,
			autoBuffering: true //Enabling auto buffering adds the first frame to the video
		}
	});
	 
}



function embed_player(playwith, shortcode, preview, divId){
	var flashversion = GetSwfVer();
	
	//document.write(flashversion);
	//playwith = 'flashhi';
	//playwith = 'qthi';
	//alert(playwith);
	
	if (!divId) 
		divId = 'player_box';
		var play_box = document.getElementById(divId);
	
	
	
	//I think this ID needs a value all the time.  IE7 seems to load with no id until a button is pressed then it behaves how it should
	
	if (playwith == 'flashhi') {
			
		play_box.innerHTML = '<a  href="'+ video_host + '/tsr3/files/videos/' + shortcode + '-hi.flv" style="display:block;width:620px;height:370px;align:center;" id="player_flow' + divId + '">';
	
		setTimeout("play_flash('player_flow" + divId + "');", 1500);
		//flowplayer("player", "assets/flash/flowplayer-3.1.1.swf");
	}
	
	else if (playwith == 'qthi') {
			if (preview == 'f') {
				play_box.innerHTML = QT_WriteOBJECT(''+ video_host + '/tsr3/files/videos/' + shortcode + '-stream.mov', '620', '390', '', // ASHIK add cdn
 'autoplay', 'false', 'emb#bgcolor', 'black', 'align', 'middle', 'id', 'qt_' + divId);
			}
			else {
				play_box.innerHTML = QT_WriteOBJECT(''+ video_host + '/tsr3/files/videos/' + shortcode + '-stream.mov', '620', '390', '', //pv/movie_expire.php?file=
 'autoplay', 'false', 'emb#bgcolor', 'black', 'align', 'middle', 'id', 'qt_' + divId);
			}
			
		}
}		
		

//CALL THE SWF 
		
		
		
		


function swapMapPhoto()
{
	Effect.toggle('photo', 'blind', {queue:'parallel'});
	Effect.toggle('map_wrapper', 'blind', {queue:'parallel'});
	if(map_created == false)
	{
		map_create();
	}
}
function map_clear()
{
	map.clearOverlays()
}
function map_set_center_zoom()
{
	if(map_top == -179 || map_bottom == -1 || map_left == 179 || map_right == 1)
	{
		map.setCenter(new GLatLng(-36.385913,158.994141), 3);
	}
	sw = new GLatLng(map_bottom, map_left);
	ne = new GLatLng(map_top, map_right);
	bounds = new GLatLngBounds(sw, ne);
	map_zoom = map.getBoundsZoomLevel(bounds)-1;
	point = new GLatLng((map_bottom+map_top)/2, (map_left+map_right)/2);
	map.setCenter(point, map_zoom);
}
function map_center(addr1, city, state, country)
{
	geocoder.getLocations(addr1+','+city+','+state+','+country,
	function (response)
	{
		if(response.Status.code != 200)
		{
			if(center)
			{
				map.setCenter(new GLatLng(-36.385913,158.994141), 3);
			}
			return;
		}	
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		map.setCenter(point, map_zoom);
	}
	);
	
}

function map_marker_test(point)
{
	if(point.lat() < map_bottom)
	{
		map_bottom = point.lat();
	}
	if(point.lat() > map_top)
	{
		map_top = point.lat();
	}
	if(point.lng() < map_left)
	{
		map_left = point.lng();
	}
	if(point.lng() > map_right)
	{
		map_right = point.lng();
	}
//	alert('mb = '+map_bottom+' ml = '+map_left+' mt = '+map_top+' mr ='+map_right);
}

function map_add_marker(addr1,city,state,country, html, open)
{
	var point;
	geocoder.getLocations(addr1+','+city+','+state+','+country,
	function (response)
	{
		if(response.Status.code != 200)
		{
			return;
		}	
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		if(place.AddressDetails.Accuracy == 8)
		{
			
			marker = new GMarker(point);
			map.addOverlay(marker);
			marker.bindInfoWindowHtml(html);
			if(open)
			{
				marker.openInfoWindowHtml(html);
			}
			
		}
//		alert('testing');
		map_marker_test(point);
//		alert('mb = '+map_bottom+' ml = '+map_left+' mt = '+map_top+' mr ='+map_right);
	}
	);
}
function map_create()
{
	if (GBrowserIsCompatible()) {

		var my_size = new GSize(380, 240);
        map = new GMap2(document.getElementById("map"), {size:my_size});
        map.addControl(new GSmallMapControl());
		geocoder = new GClientGeocoder();
		map_created = true;
		map.setCenter(new GLatLng(-36.385913,158.994141), 3);
      }
}









function showSortlink(){

	if ($('#hideBox').is(":hidden")) {

        $('#hideBox').slideDown("slow");

		$('#hideBoxHead').removeClass('lastLink');

      } else {

        $('#hideBox').slideUp("slow");

		$('#hideBoxHead').addClass('lastLink');

      }	 

}


var windowHeight =0;
var windowWidth =0;

$(document).ready(function() {

	windowWidth = $(window).width();
    windowHeight = $(window).height();
});


$(window).resize(function() {
	windowWidth = $(window).width();
    windowHeight = $(window).height();
});




function pCenter(target, width, height) {

    if (target.length > 0) {
            sWidth = windowWidth;
            sHeight = windowHeight;
            eWidth = (width) ? width : target.width();
            eHeight = (height) ? height : target.height();
            xpos = (sWidth-eWidth)/2;
            ypos = (sHeight-eHeight)/2;
            return target.css({ 'left': xpos+'px', 'top': ypos+'px', position: 'absolute' });
    }
}






/*

	----------------------------------------------------------------------------------------------------
	Accessible News Slider
	----------------------------------------------------------------------------------------------------
	
	Author:
	Brian Reindel
	
	Author URL:
	http://blog.reindel.com

	License:
	Unrestricted. This script is free for both personal and commercial use.

*/
	
	jQuery.fn.imageSlider = function( settings ) {
		settings = jQuery.extend({
	        speed : "normal",
			slideBy : 2
	    }, settings);
	    return this.each(function() {
			jQuery.fn.imageSlider.run( jQuery( this ), settings );
	    });
	};
	jQuery.fn.imageSlider.run = function( $this, settings ) {
		jQuery( ".javascript_css", $this ).css( "display", "none" );
		var ul = jQuery( "ul:eq(0)", $this );
		var li = ul.children();
		if ( li.length > settings.slideBy ) {
			
			var $next = jQuery( ".scroll_right", $this );
			var $back = jQuery( ".scroll_left", $this );
			var liWidth = jQuery( li[0] ).width();
			var animating = false;
			ul.css( "width", ( li.length * liWidth ) );
			$next.click(function() {
				if ( !animating ) {
					animating = true;
					offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
					if ( offsetLeft + ul.width() > 0 ) {
						$back.css( "display", "block" );
						ul.animate({
							left: offsetLeft
						}, settings.speed, function() {
							if ( parseInt( ul.css( "left" ) ) + ul.width() <= liWidth * settings.slideBy ) {
//								$next.css( "display", "none" );
							}
							animating = false;
						});
					} else {
						animating = false;
					}
				}
				return false;
			});
			$back.click(function() {
				if ( !animating ) {
					animating = true;
					offsetRight = parseInt( ul.css( "left" ) ) + ( liWidth * settings.slideBy );
					if ( offsetRight + ul.width() <= ul.width() ) {
						$next.css( "display", "block" );
						ul.animate({
							left: offsetRight
						}, settings.speed, function() {
							if ( parseInt( ul.css( "left" ) ) == 0 ) {
//								$back.css( "display", "none" );
							}
							animating = false;
						});
					} else {
						animating = false;
					}
				}
				return false;
			});
			$next.css( "display", "block" )
				
		}
	};
