/*GLOBAL SCRIPTS STARTS*/
$j('li.ka_signout_auth a').attr('href', 'https://www.gore-tex.com/community/logout');
/*GLOBAL SCRIPTS ENDS*/

$j(document).ready(function(){
	$j('#ka_fieldPhotoUpOpt').insertBefore('#goreFormBox3');
	$j('#fieldVideoUpOpt').insertBefore('#goreFormBox3');
	if (!window.YUKU) {
		if( (Ka.Info.PAGE === 'search/searchPage.jsp') && (Ka.Util.getLocationParam('mediaType') === 'set') ){
			$j('#ka_contentContainer h3').append('<a href="/service/displayCreateMediaSet.kickAction?as='+Ka.Info.AFFILIATESITEID+'" id="add-exp"><img src="http://clientappstest.kickapps.com/goretex/add_exp.gif" /></a>');
		}
	}
		
});


var statusHolder='';
function updateStatusProfile() {
	statusHolder = $j('#statusUpdate').val();
	FB.ensureInit(function() {
		FB.Connect.requireSession(function() {
			FB.Facebook.get_sessionState().waitUntilReady(function() {
				FB.Facebook.apiClient.users_hasAppPermission('status_update', onProfileHasAppPermission);
			});
		});               
	});         
}
 
function onProfileHasAppPermission(result, exception) {
	if (result == 1) {
		onProfileAllowStatus();
	} else {
		FB.Connect.showPermissionDialog('status_update', onProfileAllowStatus);
	}
}
 
function onProfileAllowStatus() {
	FB.Facebook.apiClient.users_setStatus(statusHolder,false,true,onStatusSuccess);
}
 
function onStatusSuccess(result, exception){
	if(result==1){
		$j('#statusStatus').html('<p>Updated!</p>');
	} else {
		$j('#statusStatus').html('<p>Oops...something went wrong! Please try again</p>');
	}
}

if(!window.YUKU) {
	Ka.Settings.tinyMCE.theme_advanced_buttons1 = "bold,italic,underline,link,unlink,forecolor,backcolor,bullist,numlist,hr,blockquote,charmap,code,emotions,kickmedia";
}

function loadScript(url, callback) {
    // adding the script tag to the head as suggested before
    var head 	= document.getElementsByTagName('head')[0];
    var script 	= document.createElement('script');
	script.type = 'text/javascript';
	script.src	 = url;

    // then bind the event to the callback function
    // there are several events for cross browser compatibility
    script.onreadystatechange = callback;
    script.onload = callback
    // fire the loading
    head.appendChild(script);
}

function loadInit(){
	if (Ka.Settings.tinyMCE.enabled) {	
		// Event for when TinyMCE is loaded 
		function tinyMceLoaded(instance) {			
			Ka.events.dispatchEvent('global-after-tinymce-init', instance);
		}
		
		// Our default settings
		var defaultSettings = {
			mode:'textareas',
			theme:'advanced',
			height : Ka.Settings.tinyMCE.defaultHeight,			
			theme_advanced_buttons1: Ka.Settings.tinyMCE.theme_advanced_buttons1,
			theme_advanced_buttons2: Ka.Settings.tinyMCE.theme_advanced_buttons2,
			theme_advanced_buttons3: Ka.Settings.tinyMCE.theme_advanced_buttons3,
			plugins : Ka.Settings.tinyMCE.plugins,
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,
			theme_advanced_resizing_min_height : Ka.Settings.tinyMCE.resizingMinHeight,
			theme_advanced_resizing_max_height : Ka.Settings.tinyMCE.resizingMaxHeight,
			theme_advanced_resize_horizontal : false,
			theme_advanced_resizing_use_cookie : false,
			button_tile_map:true,
			theme_advanced_path : false,
			editor_selector : "mediaDescription",
			relative_urls : false,
			remove_script_host : false,
			language : (Ka.Info.TINYMCELOCALE!=='')?Ka.Info.TINYMCELOCALE.split(':')[1]:'en',
			cleanup_serializer : 'xml',
			extended_valid_elements : "object[width|height|classid|codebase|id|class],param[name|value],embed[base|src|type|width|height|flashvars|wmode|name|pluginspage|align|allowScriptAccess|menu|allowFullScreen]",
			init_instance_callback : "tinyMceLoaded"
		}		
		
		// Combine platform default settings with the afiliate custom settings
		var combinedSettings;
		if (Ka.Settings.tinyMCE.customSettings) {
			combinedSettings = $j.extend({}, defaultSettings, Ka.Settings.tinyMCE.customSettings);
		} else {
			combinedSettings = defaultSettings;
		}
		
		// Ok initialize it
		if (!Ka.events.dispatchEvent('global-before-tinymce-init')) {
			// do nothing
		} else {
			tinyMCE.init(combinedSettings);
		}
	}
tinyMCE.execCommand('mceAddControl', false, 'mediaDescription');
}
if (!window.YUKU) {

	if ((Ka.Info.PAGE === 'pages/addMediaSet.jsp') || (Ka.Info.PAGE === 'pages/editSet.jsp')) {
		$j(function(){
			setTimeout(function(){
					//loadScript('/js/tinymce/jscripts/tiny_mce/tiny_mce.js');
					//$j.getScript("/js/tinymce/jscripts/tiny_mce/tiny_mce.js");
			}, 3000);
		})
	}
	
	if (Ka.Info.PAGE === 'pages/managePhoto.jsp'){
		var x = $j('.ka_searchList').html();
		x = x.replace(/Approved|Pending/ig, '');
		$j('.ka_searchList').html(x);
		$j('.ka_listDetails > strong').remove();
		$j('.ka_listAdded').prepend('<strong>Added: </strong>');
	}
}

