$(function() {
	
	//ga_trackLiked('check');
	//ga_clickout();
	
	//$('.button').click(function(){
	//	ga_track("downloadlink/"+$(this).attr('name'))
	//});	
	
	$('.buttonapple').click(function(){
		ga_track("downloadlink/apple_market");
		//window.location = _appVars.apple;
		//alert('test');
	});	
	$('.buttonandroid').click(function(){
		ga_track("downloadlink/android_market");
		//window.location = _appVars.android;
	});	
	$('.buttonblackberry').click(function(){
		ga_track("downloadlink/blackberry_market");
		//window.location = _appVars.blackberry;
	});	

	
		
	if($('.mobile').length != 0){
		$('.downloads a').hide();
		
		if(_appVars.qr == 'qr' 
				|| _appVars.med == 'm_mr' 
				|| _appVars.med == 'm_lr'
				|| _appVars.med == 'm_xlr'
				|| _appVars.med == 'm_300*50'
				|| _appVars.med == 'm_215*36'
				|| _appVars.med == 'm_168*28'
				|| _appVars.med == 'm_120*20' 
				|| _appVars.med == 'm_640*130' 
				
		){
			if(_appVars.device == 'Android' && Number(_appVars.os) >= 2.2){ga_track('android_market'); setTimeout("_gaq.push(function(){window.open(_appVars.android);});", 1000); }
			else if(_appVars.device == 'iPhone' && Number(_appVars.os) >= 4.0){ga_track('apple_market');setTimeout("_gaq.push(function(){window.open(_appVars.apple);});", 1000); }
			else if(_appVars.device == 'BlackBerry' && Number(_appVars.os) >= 4.6){ga_track('blackberry_market'); setTimeout("_gaq.push(function(){window.open(_appVars.blackberry);});", 1000); }
		}
		
		if(_appVars.device == 'Android' && Number(_appVars.os) >= 2.2){$('.android').show()}
		else if(_appVars.device == 'iPhone' && Number(_appVars.os) >= 4.0){	$('.apple').show() /*$('.appletxt').show(); $('.maintxt').hide();*/}
		else if(_appVars.device == 'BlackBerry' && Number(_appVars.os) >= 4.6){	$('.blackberry').show()}
		else{	$('.msg').show(); $('.maintxt').hide();};
	}
	
	if (_appVars.med=='testlink') {
		alert('test 7');
		_gaq.push(['_trackPageview', _appVars.page+'/'+_appVars.template+'/apple_market']);
		setTimeout("_gaq.push(function(){window.open(_appVars.apple);});", 3000);
	}
	
	$("#carousel").carousel( { pagination: true, autoSlide: true, animSpeed:'slow'} );

	if($('.facebook').length == 0){
		$(".comments_holder").toggle();
	}
	
	
	$('.deel').click(function(){
			$(".comments_holder").toggle('slide');
	});
	
	
	
	$('.close').click(function(){
			$(this).parent().parent().hide();
	});
	
	$('.popup_button').click(function(){
		
		if($('.mobile').length == 0){
			$('.page').hide();
			$('#'+$(this).attr('name')).show();
			$('.popup').show();
			return false;
		}
	
	});
	
	
});


function app_loadflash(){
	
	if($.flash.available && $('#flash_container').length > 0){	
		var flashMovie = $('#flash_container');
		$('#flash_container').html('');
		flashMovie.flash(
				{
					swf: 'flash/Header.swf',
					wmode : 'transparent',
					width: 1280,
					height: 477,
					play: false,
					flashvars: {
						language: _appVars.locale
					}
				}
			);
	}else{

	}

	
}

function app_share(site, description){
	
	msg = encodeURI(description);
	shareUrl = encodeURI(_appVars.baseUrl);
	title = encodeURI(_appVars.title);
	
	switch(site){
	case 'twitter':
		var url = "http://twitter.com/home?status="+msg+" "+shareUrl;
		var width = "600";
		var height = "300";
	break;
	case 'netlog':
		var url = "http://www.netlog.com/go/manage/links/view=save&origin=external&url="+shareUrl+"&description="+msg+"&title="+title;
		var width = "660";
		var height = "600";
	break;
	case 'facebook':
		var url = "http://www.facebook.com/sharer.php?u="+shareUrl+"&t="+msg;
		var width = "600";
		var height = "300";
	break;
		
	}
	
	popupLinkedIn = window.open(url, 'share', 'width='+width+',' +
									    'height='+height+',' +
									    'status=no,' +
									    'location=yes,' +
									    'menubar=no,' +
									    'directories=no,' +
									    'toolbar=no,' +
									    'resizable=no,' +
									    'scrollbars=no');
    popupLinkedIn.focus();
}



function app_show(ids){
		for(var id in ids){
			$(ids[id]).show();
		}
}

function app_hide(ids){
	for(var id in ids){
			$(ids[id]).css('display','none');
		}
}

function app_fadeIn(id){
	if(jQuery.browser.msie){
		$(id).show();	
	}else{
		$(id).fadeIn();
	}
}



//Track functions
function ga_track(action){
	_gaq.push(['_trackPageview', _appVars.page+'/'+_appVars.template+'/'+action]);
}

function ga_clickout(){
		$('.downloads a').click(function(){
				ga_track('clickout/'+$(this).attr('name'));
		});
}
function ga_trackLiked(likeType){
	switch(likeType){
		case 'new':
				ga_track('NewLike');	
		break;
		case 'check':
			if(_appVars.liked == '1'){
				ga_track('AlreadyLiked');
			}else{
				ga_track('NotLiked');
			}
		break;
	}
}


//Facebook functions
function fb_post(description, thumb){
	FB.ui(
  {
    method: 'feed',
    name: _appVars.title,
    link: _appVars.baseUrl,
    picture: _appVars.baseUrl+'/img/'+thumb+'.jpg',
    caption: '',
    description: description
  },
  function(response) {
    if (response && response.post_id) {
      //alert('Post was published.');
    } else {
      //alert('Post was not published.');
    }
  }
);
}

