<?php
/**
 * The Header for the template.
 *
 * @package WordPress
 */

$pp_theme_version = '1.1';

$pp_advance_enable_switcher = get_option('pp_advance_enable_switcher');
if(!empty($pp_advance_enable_switcher))
{
	session_start();
}
 
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />

<?php
$pp_seo_enable = get_option('pp_seo_enable');

if(!empty($pp_seo_enable))
{
	$pp_seo_home_title = get_option('pp_seo_home_title');
}
else
{
	$pp_seo_home_title = '';
}

if(empty($pp_seo_home_title) OR !is_home())
{
?>
<title><?php wp_title('&lsaquo;', true, 'right'); ?><?php bloginfo('name'); ?></title>
<?php
} else {
?>
<title><?php echo $pp_seo_home_title; ?></title>
<?php
}
?>

<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />


<?php
if(!empty($pp_seo_enable))
{
	$pp_seo_meta_desc = get_option('pp_seo_meta_desc');
}
else
{
	$pp_seo_meta_desc = '';
}

if(!empty($pp_seo_meta_desc))
{
?>
<meta name="description" content="<?php echo $pp_seo_meta_desc; ?>" />
<?php
}
?>
<?php
if(!empty($pp_seo_enable))
{
	$pp_seo_meta_key = get_option('pp_seo_meta_key');
}
else
{
	$pp_seo_meta_key = '';
}

if(!empty($pp_seo_meta_key))
{
?>
<meta name="keywords" content="<?php echo $pp_seo_meta_key; ?>" />
<?php
}
?>

<?php
	/**
	*	Get favicon URL
	**/
	$pp_favicon = get_option('pp_favicon');
	
	if(!empty($pp_favicon))
	{
?>
		<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/cache/<?php echo $pp_favicon; ?>" />
<?php
	}
?>

<!-- Template stylesheet -->
<?php    
    $pp_advance_combine_css = get_option('pp_advance_combine_css');
	
	if(!empty($pp_advance_combine_css))
	{	
		if(!file_exists(TEMPLATEPATH."/cache/combined.css"))
		{
			$cssmin = new CSSMin();
    		
			$css_arr = array(
			    TEMPLATEPATH.'/css/jqueryui/custom.css',
			    TEMPLATEPATH.'/css/screen.css',
			    TEMPLATEPATH.'/js/fancybox/jquery.fancybox-1.3.0.css',
			    TEMPLATEPATH.'/js/video-js.css',
			    TEMPLATEPATH.'hint.js',
			    TEMPLATEPATH.'/js/skins/vim.css',
			);
			
   			$cssmin->addFiles($css_arr);
 			
    		// Set original CSS from all files
    		$cssmin->setOriginalCSS();
    		$cssmin->compressCSS();
 			
    		$css = $cssmin->printCompressedCSS();
    		
    		file_put_contents(TEMPLATEPATH."/cache/combined.css", $css);
    	}
    	
		wp_enqueue_style("combined_css", get_stylesheet_directory_uri()."/cache/combined.css", false, $pp_theme_version);
		wp_enqueue_style("colorpicker.css", get_stylesheet_directory_uri()."/js/colorpicker/css/colorpicker.css", false, $pp_theme_version, "all");
	}
	else
	{
		wp_enqueue_style("jqueryui_css", get_stylesheet_directory_uri()."/css/jqueryui/custom.css", false, $pp_theme_version, "all");
		wp_enqueue_style("screen_css", get_stylesheet_directory_uri()."/css/screen.css", false, $pp_theme_version, "all");
		wp_enqueue_style("fancybox_css", get_stylesheet_directory_uri()."/js/fancybox/jquery.fancybox-1.3.0.css", false, $pp_theme_version, "all");
		wp_enqueue_style("videojs_css", get_stylesheet_directory_uri()."/js/video-js.css", false, $pp_theme_version, "all");
		wp_enqueue_style("vim_css", get_stylesheet_directory_uri()."/js/skins/vim.css", false, $pp_theme_version, "all");
		wp_enqueue_style("colorpicker.css", get_stylesheet_directory_uri()."/js/colorpicker/css/colorpicker.css", false, $pp_theme_version, "all");
	}
?>

<?php
	if(!empty($pp_advance_enable_switcher) && isset($_SESSION['pp_theme_style']))
	{
		$pp_theme_style = $_SESSION['pp_theme_style'];
	}
	else
	{
		$pp_theme_style = get_option('pp_theme_style');
	}

	if($pp_theme_style == 'f')
	{
		$pp_theme_style_path = get_stylesheet_directory_uri()."/css/fullwidth.css";
	}
	else
	{
		$pp_theme_style_path = '';
	}

	wp_enqueue_style("pp_theme_style", $pp_theme_style_path, false, $pp_theme_version, "all");
?>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 

<?php
	wp_enqueue_script("jquery", get_stylesheet_directory_uri()."/js/jquery.js", false, $pp_theme_version);
	wp_enqueue_script("jquery_UI_js", get_stylesheet_directory_uri()."/js/jquery-ui.js", false, $pp_theme_version);
	wp_enqueue_script("jquery_cufon", get_stylesheet_directory_uri()."/js/cufon.js", false, $pp_theme_version);
	wp_enqueue_script("colorpicker.js", get_stylesheet_directory_uri()."/js/colorpicker.js", false, $pp_theme_version);
	wp_enqueue_script("eye.js", get_stylesheet_directory_uri()."/js/eye.js", false, $pp_theme_version);
	wp_enqueue_script("utils.js", get_stylesheet_directory_uri()."/js/utils.js", false, $pp_theme_version);
		
	/**
	*	Check selected font
	**/
	if(!empty($pp_advance_enable_switcher) && isset($_SESSION['pp_font']))
	{
		$pp_font = $_SESSION['pp_font'];
	}
	else
	{
		$pp_font = get_option('pp_font');
	}
	
	if(empty($pp_font))
	{
		$pp_font = 'Vegur_300.font';
	}
		
	wp_enqueue_script("cufon_font", get_stylesheet_directory_uri()."/fonts/".$pp_font.".js", false, $pp_theme_version);
	
	$js_path = TEMPLATEPATH."/js/";
	$js_arr = array(
	    'fancybox/jquery.fancybox-1.3.0.js',
	    'jquery.easing.js',
	    'anythingSlider.js',
	    'gmap.js',
	    'hint.js',
	    'jquery.validate.js',
	    'browser.js',
	    'video.js',
	    'jquery.tipsy.js',
	    'jquery.quicksand.js',
	    'jquery.nivoslider.js',
	    'custom.js',
	);
	$js = "";

	$pp_advance_combine_js = get_option('pp_advance_combine_js');
	
	if(!empty($pp_advance_combine_js))
	{	
		if(!file_exists(TEMPLATEPATH."/cache/combined.js"))
		{
			foreach($js_arr as $file) {
				if($file != 'jquery.js' && $file != 'jquery-ui.js')
				{
    				$js .= JSMin::minify(file_get_contents($js_path.$file));
    			}
			}
			
			file_put_contents(TEMPLATEPATH."/cache/combined.js", $js);
		}

		wp_enqueue_script("combined_js", get_stylesheet_directory_uri()."/cache/combined.js", false, $pp_theme_version);
	}
	else
	{
		foreach($js_arr as $file) {
			if($file != 'jquery.js' && $file != 'jquery-ui.js')
			{
				wp_enqueue_script($file, get_stylesheet_directory_uri()."/js/".$file, false, $pp_theme_version);
			}
		}
	}
?>

<?php
	/* Always have wp_head() just before the closing </head>
	 * tag of your theme, or you will break many plugins, which
	 * generally use this hook to add elements to <head> such
	 * as styles, scripts, and meta tags.
	 */
	wp_head();
?>

<!--[if lt IE 8]>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/css/ie7.css?v=<?php echo $pp_theme_version; ?>" type="text/css" media="all"/>
<![endif]-->

<!--[if lte IE 8]>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/css/ie?v=<?php echo $pp_theme_version; ?>.css" type="text/css" media="all"/>
<![endif]-->

<style>
<?php
	if(!empty($pp_advance_enable_switcher) && isset($_SESSION['pp_body_font']))
	{
		$pp_body_font = $_SESSION['pp_body_font'];
	}
	else
	{
		$pp_body_font = get_option('pp_body_font');
	}
	
	if(!empty($pp_body_font))
	{
?>
body, input[type=submit], input[type=button], a.button, input[type=submit].medium, input[type=button].medium, a.button.medium, input[type=submit].large, input[type=button].large, a.button.large { font-family:<?php echo $pp_body_font; ?>; }
<?php
	}
	
?>

<?php
	$pp_body_font_size = get_option('pp_body_font_size');
	
	if(!empty($pp_body_font_size))
	{
?>
body { font-size:<?php echo $pp_body_font_size; ?>px; }
<?php
	}
	
?>

<?php
	if(!empty($pp_advance_enable_switcher) && isset($_SESSION['pp_bg_color']))
	{
		$pp_bg = $_SESSION['pp_bg_color'];
	}
	else
	{
		$pp_bg = get_option('pp_bg');
	}
	
	if(!empty($pp_bg))
	{
?>
body, .tagline, #footer, #footer_shadow { background-color:<?php echo $pp_bg; ?>; }
<?php
	}
	
?>

<?php
	$pp_menu_color = get_option('pp_menu_color');
	
	if(!empty($pp_menu_color))
	{
?>
#menu_wrapper .nav ul li a, #menu_wrapper div .nav li a { color:<?php echo $pp_menu_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_tagline_font_size = get_option('pp_tagline_font_size');
	
	if(!empty($pp_tagline_font_size))
	{
?>
.tagline_header { font-size:<?php echo $pp_tagline_font_size; ?>px; }
<?php
	}
	
?>

<?php
	$pp_tagline_font_color = get_option('pp_tagline_font_color');
	
	if(!empty($pp_tagline_font_color))
	{
?>
h1.tagline_header { color:<?php echo $pp_tagline_font_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_h1_font_color = get_option('pp_h1_font_color');
	
	if(!empty($pp_h1_font_color))
	{
?>
h1,h2,h3,h4,h5,h6 { color:<?php echo $pp_h1_font_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_h1_size = get_option('pp_h1_size');
	
	if(!empty($pp_h1_size))
	{
?>
h1 { font-size:<?php echo $pp_h1_size; ?>px; }
<?php
	}
	
?>

<?php
	$pp_h2_size = get_option('pp_h2_size');
	
	if(!empty($pp_h2_size))
	{
?>
h2 { font-size:<?php echo $pp_h2_size; ?>px; }
<?php
	}
	
?>

<?php
	$pp_h3_size = get_option('pp_h3_size');
	
	if(!empty($pp_h3_size))
	{
?>
h3 { font-size:<?php echo $pp_h3_size; ?>px; }
<?php
	}
	
?>

<?php
	$pp_h4_size = get_option('pp_h4_size');
	
	if(!empty($pp_h4_size))
	{
?>
h4 { font-size:<?php echo $pp_h4_size; ?>px; }
<?php
	}
	
?>

<?php
	$pp_h5_size = get_option('pp_h5_size');
	
	if(!empty($pp_h5_size))
	{
?>
h5 { font-size:<?php echo $pp_h5_size; ?>px; }
<?php
	}
	
?>

<?php
	$pp_h6_size = get_option('pp_h6_size');
	
	if(!empty($pp_h6_size))
	{
?>
h6 { font-size:<?php echo $pp_h6_size; ?>px; }
<?php
	}
	
?>

<?php
	$pp_font_color = get_option('pp_font_color');
	
	if(!empty($pp_font_color))
	{
?>
body { color:<?php echo $pp_font_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_link_color = get_option('pp_link_color');
	
	if(!empty($pp_link_color))
	{
?>
a { color:<?php echo $pp_link_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_hover_link_color = get_option('pp_hover_link_color');
	
	if(!empty($pp_hover_link_color))
	{
?>
a:hover, a:active { color:<?php echo $pp_hover_link_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_button_bg_color = get_option('pp_button_bg_color');
	
	if(!empty($pp_button_bg_color))
	{
		$pp_button_bg_color_light = '#'.hex_lighter(substr($pp_button_bg_color, 1), 100);
?>
input[type=submit], input[type=button], a.button { 
	background: <?php echo $pp_button_bg_color; ?>;
	background: -webkit-gradient(linear, left top, left bottom, from(<?php echo $pp_button_bg_color_light; ?>), to(<?php echo $pp_button_bg_color; ?>));
	background: -moz-linear-gradient(top,  <?php echo $pp_button_bg_color_light; ?>,  <?php echo $pp_button_bg_color; ?>);
	filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='<?php echo $pp_button_bg_color_light; ?>', endColorstr='<?php echo $pp_button_bg_color; ?>');
}
input[type=submit]:active, input[type=button]:active, a.button:active
{
	background: <?php echo $pp_button_bg_color; ?>;
	background: -webkit-gradient(linear, left top, left bottom, from(<?php echo $pp_button_bg_color; ?>), to(<?php echo $pp_button_bg_color_light; ?>));
	background: -moz-linear-gradient(top,  <?php echo $pp_button_bg_color; ?>,  <?php echo $pp_button_bg_color_light; ?>);
	filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='<?php echo $pp_button_bg_color_light; ?>', endColorstr='<?php echo $pp_button_bg_color; ?>');
}
<?php
	}
	
?>

<?php
	$pp_button_font_color = get_option('pp_button_font_color');
	
	if(!empty($pp_button_font_color))
	{
?>
input[type=submit], input[type=button], a.button { 
	color: <?php echo $pp_button_font_color; ?>;
}
input[type=submit]:hover, input[type=button]:hover, a.button:hover
{
	color: <?php echo $pp_button_font_color; ?>;
}
<?php
	}
	
?>

<?php
	$pp_button_border_color = get_option('pp_button_border_color');
	
	if(!empty($pp_button_border_color))
	{
?>
input[type=submit], input[type=button], a.button { 
	border: 1px solid <?php echo $pp_button_border_color; ?>;
}
<?php
	}
	
?>

<?php
	$pp_footer_font_color = get_option('pp_footer_font_color');
	
	if(!empty($pp_footer_font_color))
	{
?>
#footer, #footer ul { color:<?php echo $pp_footer_font_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_footer_link_color = get_option('pp_footer_link_color');
	
	if(!empty($pp_footer_link_color))
	{
?>
#footer a { color:<?php echo $pp_footer_link_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_footer_hover_link_color = get_option('pp_footer_hover_link_color');
	
	if(!empty($pp_footer_hover_link_color))
	{
?>
#footer a:hover, #footer a:active { color:<?php echo $pp_footer_hover_link_color; ?>; }
<?php
	}
	
?>

<?php
	$pp_slider_height = get_option('pp_slider_height');
	
	if(!empty($pp_slider_height))
	{
?>
#anything_slider, .slideshow, .home_gallery, #anything_slider .wrapper, .slideshow .wrapper, .home_gallery .wrapper, #anything_slider ul li, .slideshow ul li, #slider_loading, #slider_wrapper { height:<?php echo $pp_slider_height; ?>px; }
<?php
	}
	
?>

<?php
	$header_wrapper_height = 500-(400-$pp_slider_height);
	$arrow_top = 340-(400-$pp_slider_height);
?>
body.home #header_wrapper { height:<?php echo $header_wrapper_height; ?>px; }
#anything_slider .arrow, .slideshow .arrow { top:<?php echo $arrow_top; ?>px; }

<?php
	$pp_page_caption_align = get_option('pp_page_caption_align');
	if(!empty($pp_page_caption_align))
	{
?>
.caption_inner { text-align: <?php echo $pp_page_caption_align; ?> }
<?php
	}
?>

</style>

<?php
if(is_front_page())
{
?>
<script>
$j(document).ready(function(){ 
	$j('#menu_wrapper .menu-main-menu-container .nav li a[title=Home]').parent('li').addClass('current-menu-item');
});
</script>
<?php
}
?>

<?php
	/**
	*	Get custom CSS
	**/
	$pp_custom_css = get_option('pp_custom_css');
	
	
	if(!empty($pp_custom_css))
	{
		echo '<style>';
		echo stripslashes($pp_custom_css);
		echo '</style>';
	}
?>

</head>

<?php

/**
*	Get Current page object
**/
$page = get_page($post->ID);


/**
*	Get current page id
**/
$current_page_id = '';

if(isset($page->ID))
{
    $current_page_id = $page->ID;
}

?>

<body <?php body_class(); ?>>

	<input type="hidden" id="pp_stylesheet_directory" name="pp_stylesheet_directory" value="<?php echo get_stylesheet_directory_uri(); ?>"/>
	<?php
		$pp_portfolio_sorting = get_option('pp_portfolio_sorting');
	?>
	<input type="hidden" id="pp_portfolio_sorting" name="pp_portfolio_sorting" value="<?php echo $pp_portfolio_sorting; ?>"/>
	<?php
		$pp_footer_style = get_option('pp_footer_style');
	?>
	<input type="hidden" id="pp_footer_style" name="pp_footer_style" value="<?php echo $pp_footer_style; ?>"/>
	
	<!-- Begin template wrapper -->
	<div id="wrapper">
			
		<!-- Begin header -->
		<div id="header_wrapper">
			<div id="top_bar">
					<div class="logo">
						<!-- Begin logo -->
					
						<?php
							//get custom logo
							$pp_logo = get_option('pp_logo');
							
							if(empty($pp_logo))
							{
								$pp_logo = get_stylesheet_directory_uri().'/images/logo.png';
							}
							else
							{
								$pp_logo = get_stylesheet_directory_uri().'/cache/'.$pp_logo;
							}

						?>
						
						<a id="custom_logo" href="<?php echo home_url(); ?>"><img src="<?php echo $pp_logo?>" alt=""/></a>
						
						<!-- End logo -->
					</div>
					
					<!-- Begin main nav -->
					<div id="menu_wrapper">
					
					    <?php 	
					    			//Get page nav
					    			wp_nav_menu( 
					    					array( 
					    						'menu_id'			=> 'main_menu',
					    						'menu_class'		=> 'nav',
					    						'theme_location' 	=> 'primary-menu',
					    					) 
					    			); 
					    ?>
					
					</div>
					<!-- End main nav -->
					
				</div>
				
				<?php
					if(!empty($pp_advance_enable_switcher))
					{
				?>
				<form action="<?php echo get_stylesheet_directory_uri(); ?>/option.php" method="get" id="form_option" name="form_option">
					<div id="option_wrapper">
					<div class="inner">
						Background Color<br/>
						<div id="bg_preview" class="colorpicker_preview" style="background:<?php echo $pp_bg; ?>;margin-top:5px">&nbsp;</div>
						<input type="hidden" id="pp_bg_color" name="pp_bg_color" value="<?php echo $pp_bg; ?>" />
						<br/>
						
						
						Theme Style<br/>
						<select id="pp_theme_style_select" name="pp_theme_style_select">
							<option value="fx" <?php if($pp_theme_style == 'fx') echo 'selected="selected"'; ?>>Fixed Width</option>
							<option value="f" <?php if($pp_theme_style == 'f') echo 'selected="selected"'; ?>>Full Width</option>
						</select>
						<br/><br/>
						
						<?php
							$pp_handle = opendir(TEMPLATEPATH.'/fonts');
							$pp_font_arr = array();
							
							while (false!==($pp_file = readdir($pp_handle))) {
								if ($pp_file != "." && $pp_file != ".." && $pp_file != ".DS_Store") {
									$pp_file_name = basename($pp_file, '.js');
									
									if($pp_file_name != 'Quicksand_300.font')
									{
										$pp_name = explode('_', $pp_file_name);
									
										$pp_font_arr[$pp_file_name] = $pp_file_name;
									}
								}
							}
							closedir($pp_handle);
							asort($pp_font_arr);
						?>
						Header Font<br/>
						<select name="pp_font" id="pp_font">
							<?php
								if(is_array($pp_font_arr) && !empty($pp_font_arr))
								{
									foreach($pp_font_arr as $key => $font)
									{
										$selected = '';
										if($font == $pp_font)
										{
											$selected = 'selected="selected"';
										}
							?>
										<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $font; ?></option>
							<?php
									}
								}
							?>
						</select>
						<br/><br/>
						
						Content Font<br/>
						<select name="pp_body_font" id="pp_body_font">
							<option value="Arial,Verdana,sans-serif" <?php if($pp_body_font=='Arial,Verdana,sans-serif'){ echo 'selected="selected"'; } ?>>Arial</option>
							<option value="Lucida Grande,Arial,Verdana,sans-serif" <?php if($pp_body_font=='Lucida Grande,Arial,Verdana,sans-serif'){ echo 'selected="selected"'; } ?>>Lucida Grande</option>
							<option value="Verdana,Arial,sans-serif" <?php if($pp_body_font=='Verdana,Arial,sans-serif'){ echo 'selected="selected"'; } ?>>Verdana</option>
							<option value="Helvatica,Arial,sans-serif" <?php if($pp_body_font=='Helvatica,Arial,sans-serif'){ echo 'selected="selected"'; } ?>>Helvatica</option>
							<option value="Georgia, Times, serif" <?php if($pp_body_font=='Georgia, Times, serif'){ echo 'selected="selected"'; } ?>>Georgia</option>
						</select>
						
						<br/><br/><br/>
						<a class="button" href="<?php echo get_stylesheet_directory_uri(); ?>/switcher.php?reset=1" style="width:54px">Reset</a>
					</div>
					</div>
					<div id="option_btn">
						<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/color.png"/>
					</div>
				</form>
				<?php
					}
				?>
				
				<br class="clear"/>