<?php
// SCRIPTCALLER - ADD THE SCRIPTS  
global $post, $options, $allslider_settings, $fonts, $gfonts, $shortname ;


foreach ($options as $value) 
	{
	if (isset($value['id']) && get_option( $value['id'] ) != FALSE ) 
		{
	            	$$value['id'] = get_option( $value['id'] ); 
		}
	}
 



add_action('init', 'call_the_scripts'); 

function call_the_scripts()
	{
	global $post;
	wp_register_script( 'cufon', get_template_directory_uri().'/script/cufon.js' ,'','',TRUE);
	wp_register_script( 'mobilemenu', get_template_directory_uri().'/script/jquery.mobilemenu.js' ,'','',TRUE); 
	wp_register_script( 'scrollbar', get_template_directory_uri().'/script/jquery.scrollbar.js','','',TRUE ); 
	wp_register_script( 'Custom', get_template_directory_uri().'/script/custom.js.php','','',TRUE );
	wp_register_script( 'Prettyphoto', get_template_directory_uri().'/script/jquery.prettyPhoto.js' ,'','',TRUE); 
	wp_register_script( 'Superfish', get_template_directory_uri().'/script/superfish.js' ,'','',TRUE);  
	wp_register_script( 'flex', get_template_directory_uri().'/script/jquery.flexslider-min.js','','',TRUE );   
	wp_register_script( 'mobile', get_template_directory_uri().'/script/mobile.js','','',TRUE );   
 

	wp_enqueue_script( 'jquery','','','',true ); 
	wp_enqueue_script('jquery-ui-core');
	wp_enqueue_script('jquery-ui-draggable');
	wp_enqueue_script('jquery-ui-tabs');
	wp_enqueue_script('jquery-ui-accordion');
	wp_enqueue_script('jquery-ui-sortable');
	wp_enqueue_script('jquery-ui-selectable');
	wp_enqueue_script('jquery-ui-dialog');
	wp_enqueue_script('jquery-ui-datepicker');
	wp_enqueue_script('jquery-ui-widget'); 
	wp_enqueue_script( 'Superfish' );
	wp_enqueue_script( 'Prettyphoto' ); 
	wp_enqueue_script( 'cufon' ); 
	wp_enqueue_script( 'easing' ); 
	wp_enqueue_script( 'Custom' );  
	wp_enqueue_script( 'flex' );
	
	} 







function scribble_call_styles()
	{
	if(!is_admin())
		{
		wp_enqueue_style('theme-css', get_template_directory_uri() . '/style.css', false); 
		wp_enqueue_style('custom-css', get_template_directory_uri() . '/css/customcss.php', false); 
		wp_enqueue_style('prettyPhoto-css', get_template_directory_uri() . '/css/prettyPhoto.css', false); 
		}
	}

add_action('init', 'scribble_call_styles'); 















add_action('wp_head', 'emc2_call_cufon'); 
add_action('wp_head', 'emc2_call_custom_scripts'); 
add_action('wp_head', 'emc2_call_webfonts'); 
add_action('wp_head', 'emc2_call_custom_styles'); 




// CUFON FONTS

function emc2_call_cufon()
	{ 
	global $cufon_fonts;
	if($cufon_fonts!="")
		{
		foreach((array)$cufon_fonts as $font => $data) 
			{
			echo "<script type='text/javascript' src='".$data['file_url']."'></script>";
			}
		} 
	$return='<script type="text/javascript">';
	if(load_option("cufon_h1")!="") { $return.= "Cufon.replace('h1', {fontFamily: \"".stripslashes(load_option("cufon_h1"))."\"}); ";  } 
	if(load_option("cufon_h2")!="") { $return.= "Cufon.replace('h2', {fontFamily: \"".stripslashes(load_option("cufon_h2"))."\"}); ";  } 
	if(load_option("cufon_h3")!="") { $return.= "Cufon.replace('h3', {fontFamily: \"".stripslashes(load_option("cufon_h3"))."\"}); "; } 
	$return.='</script>';
	echo $return."\n"; 
	}



// GOOGLE WEBMASTER TOOLS 

function emc2_call_custom_scripts()
	{ 
	if(load_option("google_webmaster"))
		{
		echo stripslashes(load_option("google_webmaster")."\n");
		} 
	} 


// GOOGLE WEBFONTS

function emc2_call_webfonts()
	{	
	global $options, $gfonts;
	foreach ($options as $value) 
		{
		if($value['type']=="font")	
			{
			$tarr=get_option($value['id']);
			if($tarr!="")
				{
				$arr[]=$tarr;
				}
			}
		}
	$used_fonts="";
	$arr=array_unique($arr);
	for($i=0;$i<count($arr); $i++)
		{
		if(in_array($arr[$i],$gfonts))
			{
			$arr[$i]=ucwords($arr[$i]);
			if($arr[$i]!="") { $my_font=str_replace(" ","+",$arr[$i]); $used_fonts.=$my_font."|"; }
			}
	
		}
	if(isset($used_fonts))
		{
		if($used_fonts!="") 
			{ 
			echo "<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=".$used_fonts."' />\n";
			}
		}
	}


// CUSTOM STYLES

function emc2_call_custom_styles()
	{
	$cbg=get_post_custom_values('cbg');
	$bgcolor=get_post_custom_values("bgcolor");
	$cx=get_post_custom_values("cx");
	$cy=get_post_custom_values("cy");
	$crep=get_post_custom_values("crep");
	$cfix=get_post_custom_values("cfix"); 
	$return="";
	if($bgcolor)
		{
		$return.='#cbackground {background-color:'.$bgcolor[0].'}';	
		} 
	if($cbg[0])
		{
		$return.='#cbackground {background:url('.$cbg[0].') '.$cx[0].' '.$cy[0].' '.$crep[0];
		if($cfix[0]=="on") 
			{ 
			$return.= " fixed";
			}
		$return.='}';
	}
	if($return!="")
		{
		$ret="<style type='text/css'>";
		$ret.=$return;
		$ret.='</style>';
		echo $ret;
		} 
	}


























